PHP5 operates on the MySQL database. 1. create a database connection? Php $ mysqlinewmysqli (localhost, root, mydb );? To establish a database connection, four parameters are required: database address, database access username, and data. 1. create a database connection.
$ Mysqli = new mysqli ("localhost", "root", "", "mydb ");
?>
To establish a database connection, four parameters are required: database address, database access username, database access password, and database name. In addition to using the above mysqli object constructor to establish a database connection, you can also call its connect method to establish a database connection.
$ Mysqli = new mysqli ();
$ Mysqli-> connect ("localhost", "root", "", "mydb ");
?>
You can also use the mysqli object constructor to establish a data connection and use the select_db method to specify the database to be accessed.
$ Mysqli = new mysqli ("localhost", "root ","");
$ Mysqli-> select_db ("mydb ");
?>
Get the error code of the current connection through the errno attribute of the mysqli object. if there is no error in the current connection, the error code is returned as 0.
$ Mysqli = new mysqli ("localhost", "root ","");
$ Mysqli-> select_db ("mydb ");
If ($ mysqli-> errno = 0) // checks whether the current connection is successful.
{
}
Else
{
Echo "The Connection is Error! ";
Exit ();
}
?>
Of course, you can use the error attribute of the mysqli object to get the error message of the current connection. if there is no error, "" is returned.
$ Mysqli = new mysqli ("localhost", "rootsss ","");
$ Mysqli-> select_db ("mydb ");
If ($ mysqli-> errno = 0) // checks whether the current connection is successful.
{
}
Else
{
Echo $ mysqli-> error; // output the current error message
Exit ();
}
?>
- 5 pages in total:
- Previous Page
- 1
- 2
- 3
- 4
- 5
- Next page
Http://www.bkjia.com/PHPjc/364344.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/364344.htmlTechArticle1. create database connection? Php $ mysqli = new mysqli (localhost, root, mydb );? To establish a database connection, four parameters are required: database address, database access username, and data...