Copy code The code is as follows:
require_once "DB.php"; // Contains class Library file
$conn = DB::connect("mysql://root:1981427@localhost/test"); //Connect to database
if (!DB::isError($conn)) { // Determine whether the connection is successful
print "Database connection successful";
}
else
{
echo "Database connection failed!";
}
?>
Copy code The code is as follows:
require_once "DB.php";
$conn = DB::connect("mysql://root:1981427@localhost/test"); //Call connect to connect to the database
if (DB::isError($conn)) //If the connection error occurs Then an error is reported
{
print "Database connection failed";
}
$rs = $conn->query("select id,username, password from tablename1"); //Execute SQL statement
if (DB::isError($rs)) //Determine whether the execution is successful
{
print "Data query failed";
}
while ($rs->fetchInto( $rows)) //Loop to output query results
{
print "Number: $rows[0]
";
print "Name: $rows[1]
" ;
print "Password: $rows[2]
";
print "
";
}
?>
Copy code The code is as follows:
require_once "DB.php";
$conn = DB: :connect("mysql://root:1981427@localhost/test"); //Call connect to connect to the database
if (DB::isError($conn)) //If the connection error occurs, an error will be reported
{
print "Database connection failed";
}
//Execute the SQL statement and return 1 record starting from record 0
$rs = $conn->limitQuery("select id,username, password from tablename1",2,5); //Query the third to sixth data in the record set
if (DB::isError($rs)) //If there is an error in the query, an error will be reported
{
print "Data query failed";
}
while ($rs->fetchInto($rows)) //Loop to output query results
{
print "Number: $rows[0 ]
";
print "Name: $rows[1]
";
print "Password: $rows[2]
";
print "< HR>";
}
?>
Copy code The code is as follows:
require_once "DB.php";
$conn = DB::connect("mysql://root:1981427@localhost/test"); //Connect to the database
if (DB::isError($conn))
{
print "Database connection failed";
}
//Use prepare function to prepare SQL statements
$rs = $conn-> prepare("update tablename1 set password = 'Susan' where id = '1'");
if (DB::isError($rs))
{
print "Data update failed";
}
else
{
$conn->execute($rs); //Execute SQL statement to update the database
print "Data update successful";
}
?> ;
http://www.bkjia.com/PHPjc/319873.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319873.htmlTechArticleCopy the code as follows: ?php require_once "DB.php"; //Include class library file $conn = DB ::connect("mysql://root:1981427@localhost/test"); //Connect to the database if (!DB::isError($conn)) {...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn