Phpdb class library for database operations _ PHP Tutorial

Source: Internet
Author: User
The phpdb class library performs database operations. Copy the code as follows :? Phprequire_onceDB.php; contains the class library file $ connDB: connect (mysql: root: 1981427 @ localhosttest); connects to the database if (! DB: isError ($ conn )){ The code is as follows:


Require_once "DB. php"; // contains the class library file
$ Conn = DB: connect ("mysql: // root: 1981427 @ localhost/test"); // connect to the database
If (! DB: isError ($ conn) {// Determine whether the connection is successful
Print "database connection successful ";
}
Else
{
Echo "database connection failed! ";
}
?>


The code is as follows:


Require_once "DB. php ";
$ Conn = DB: connect ("mysql: // root: 1981427 @ localhost/test"); // Call connect to the database
If (DB: isError ($ conn) // if a connection error occurs, an error is returned.
{
Print "database connection failed ";
}
$ Rs = $ conn-> query ("select id, username, password from tablename1"); // execute an SQL statement
If (DB: isError ($ rs) // You can check whether the execution is successful.
{
Print "data query failed ";
}
While ($ rs-> fetchInto ($ rows) // cyclically outputs the query results
{
Print "No.: $ rows [0]
";
Print "name: $ rows [1]
";
Print "Password: $ rows [2]
";
Print "";
}
?>


The code is as follows:


Require_once "DB. php ";
$ Conn = DB: connect ("mysql: // root: 1981427 @ localhost/test"); // Call connect to the database
If (DB: isError ($ conn) // if a connection error occurs, an error is returned.
{
Print "database connection failed ";
}
// Execute the SQL statement and return one record from 0th
$ Rs = $ conn-> limitQuery ("select id, username, password from tablename1",); // query the third to sixth data records in the record set
If (DB: isError ($ rs) // if an error occurs in the query, an error is returned.
{
Print "data query failed ";
}
While ($ rs-> fetchInto ($ rows) // cyclically outputs the query results
{
Print "No.: $ rows [0]
";
Print "name: $ rows [1]
";
Print "Password: $ rows [2]
";
Print "";
}
?>


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 the prepare function to prepare SQL statements
$ Rs = $ conn-> prepare ("update tablename1 set password = 'use' where id = '1 '");
If (DB: isError ($ rs ))
{
Print "data update failed ";
}
Else
{
$ Conn-> execute ($ rs); // execute an SQL statement to update the database
Print "data updated ";
}
?>

The http://www.bkjia.com/PHPjc/319873.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/319873.htmlTechArticle code is as follows :? Php require_once "DB. php "; // contains the class library file $ conn = DB: connect (" mysql: // root: 1981427 @ localhost/test "); // connect to the 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.