PHP dB class library for database operations

Source: Internet
Author: User

CopyCode The 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 the Code 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.
{< br> Print "database connection failed ";
}< br> $ rs = $ Conn-> query ("select ID, username, password from tablename1"); // execute an SQL statement
If (DB:: iserror ($ RS) // determines whether execution is successful
{< br> Print "Data Query failed ";
}< br> while ($ RS-> fetchinto ($ rows) // output the query result cyclically
{< br> Print "no.: $ Rows [0]
";
Print" Name: $ rows [1]
";
Print" password: $ rows [2]
";
Print"

";
}< BR >?>

copy the Code 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,
{< br> Print "database connection failed";
}< br> // run the SQL statement, returns one record starting with 0th records
$ 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 during query, an error is returned.
{< br> Print "Data Query failed";
}< br> while ($ RS-> FET Chinto ($ rows) // cyclically output query results
{< br> Print "No.: $ rows [0]
";
Print "Name: $ rows [1]
";
Print" Password: $ rows [2]
";
Print"

";
}< BR >?>

copy the 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)
{< br> Print "database connection failed ";
}< br> // use the prepare function to prepare an SQL statement
$ rs = $ Conn-> prepare ("Update tablename1 SET Password = 'Susan 'where id =' 1 '");
If (DB: iserror ($ RS)
{< br> Print "data update failed ";
}< br> else
{< br> $ Conn-> execute ($ RS); // Execute SQL statements to update the database
Print "data more New success ";
}< BR >?>

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.