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