Php db class library for database operations

Source: Internet
Author: User

Copy codeThe 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) {// determine whether the connection is successful
Print "database connection successful ";
}
Else
{
Echo "database connection failed! ";
}
?>

Copy codeThe Code is as follows:
<? Php
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] <BR> ";
Print "Name: $ rows [1] <BR> ";
Print "Password: $ rows [2] <BR> ";
Print "<HR> ";
}
?>

Copy codeThe Code is as follows:
<? Php
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] <BR> ";
Print "Name: $ rows [1] <BR> ";
Print "Password: $ rows [2] <BR> ";
Print "<HR> ";
}
?>

Copy codeThe Code is as follows:
<? Php
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 ";
}
?>

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.