PHP DB Class library for database operations _php Tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
Require_once "db.php"; Include Class library files
$conn = Db::connect ("Mysql://root:1981427@localhost/test"); Connecting to a database
if (! Db::iserror ($conn)) {//Determine if the connection is successful
Print "Database connection succeeded";
}
Else
{
echo "Database connection failed! ";
}
?>

Copy CodeThe code is as follows:
Require_once "db.php";
$conn = Db::connect ("Mysql://root:1981427@localhost/test"); Call the Connect connection database
if (Db::iserror ($conn))//error if connection is faulted
{
Print "Database connection failed";
}
$rs = $conn->query ("Select Id,username, password from tablename1"); Execute SQL statement
if (Db::iserror ($RS))//Determine if execution succeeded
{
Print "Data query failed";
}
while ($rs->fetchinto ($rows))//Loop output query Results
{
Print "No.: $rows [0]
";
Print "Name: $rows [1]
";
Print "Password: $rows [2]
";
Print "";
}
?>

Copy CodeThe code is as follows:
Require_once "db.php";
$conn = Db::connect ("Mysql://root:1981427@localhost/test"); Call the Connect connection database
if (Db::iserror ($conn))//error if connection is faulted
{
Print "Database connection failed";
}
Executes the SQL statement and returns 1 records starting with the No. 0 entry
$rs = $conn->limitquery ("Select Id,username, password from tablename1", 2,5); Querying the third to sixth data in a recordset
if (Db::iserror ($RS))//error if query is wrong
{
Print "Data query failed";
}
while ($rs->fetchinto ($rows))//Loop output query Results
{
Print "No.: $rows [0]
";
Print "Name: $rows [1]
";
Print "Password: $rows [2]
";
Print "";
}
?>

Copy CodeThe code is as follows:
Require_once "db.php";
$conn = Db::connect ("Mysql://root:1981427@localhost/test"); Connecting to a database
if (Db::iserror ($conn))
{
Print "Database connection failed";
}
Preparing SQL statements using the Prepare function
$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 Update database
Print "Data update success";
}
?>

http://www.bkjia.com/PHPjc/319873.html www.bkjia.com true http://www.bkjia.com/PHPjc/319873.html techarticle Copy the code as follows: PHP require_once "db.php";//contains class library file $conn = Db::connect ("Mysql://root:1981427@localhost/test");//Connect to Database if (! Db::iserror ($conn)) {...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.