PHP DB Class library for database Operation _php Foundation

Source: Internet
Author: User
Tags prepare

Copy Code code as follows:

<?php
Require_once "db.php"; Include Class library files
$conn = Db::connect ("Mysql://root:1981427@localhost/test"); Connecting to a database
if (! Db::iserror ($conn)) {//To determine whether the connection was successful
Print "Database connection succeeded";
}
Else
{
echo Database connection Failed! ";
}
?>

Copy Code code as follows:

<?php
Require_once "db.php";
$conn = Db::connect ("Mysql://root:1981427@localhost/test"); Calling Connect connection Database
if (Db::iserror ($conn))////If the connection is wrong, error
{
Print "Database connection failed";
}
$rs = $conn->query ("Select Id,username, password from tablename1"); Execute SQL statement
if (Db::iserror ($RS))//Determine whether the execution succeeds
{
Print "Data query failed";
}
while ($rs->fetchinto ($rows))//Loop output query Results
{
Print "Number number: $rows [0]<br>";
Print "Name: $rows [1]<br>";
Print "Password: $rows [2]<br>";
print "<HR>";
}
?>

Copy Code code as follows:

<?php
Require_once "db.php";
$conn = Db::connect ("Mysql://root:1981427@localhost/test"); Calling Connect connection Database
if (Db::iserror ($conn))////If the connection is wrong, error
{
Print "Database connection failed";
}
Executes the SQL statement, returning 1 records starting from article No. 0
$rs = $conn->limitquery ("Select Id,username, password from tablename1", 2,5); Query out third to sixth data in a recordset
if (Db::iserror ($RS))////If the query fails, the error occurs
{
Print "Data query failed";
}
while ($rs->fetchinto ($rows))//Loop output query Results
{
Print "Number: $rows [0]<br>";
Print "Name: $rows [1]<br>";
Print "Password: $rows [2]<br>";
print "<HR>";
}
?>

Copy Code code as follows:

<?php
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 succeeded";
}
?>

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.