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 )){...