Two ways of php+mysqli database connection, mysqli database connection
The examples in this article describe two methods of php+mysqli database connection. Share it with everyone for your reference. The details are as follows:
Here is a comparison of two methods of mysqli database connection, namely object-oriented and process-oriented. The code is as follows:
The first way: establish database connection in object-oriented way
Copy code The code is as follows:
$mysqli = new MySQLi("localhost","root","1233456");//Default MySQL class, its properties and methods can be found in the manual
if($mysqli->connect_error){//connect_error is an attribute and an error is reported
die("Database connection failed: ".$mysqli->connect_errno."--".$mysqli->connect_error); // connect_errno: error number
}
$mysqli->select_db("liuyan");//Select database
$mysqli->query("set names 'GBK'");
Second way: Establish a database connection in a process-oriented way, this is similar to the mysql extension library
Copy code The code is as follows:
$conn = @mysqli_connect("localhost","root","123456") or die(mysqli_connect_error() );
mysqli_select_db($conn,"liuyan") or die(mysqli_connect_error());//Unlike the mysql extension library, the database name is written at the end, and $conn is required
mysqli_query($conn,"set names 'GBK'");//Same as above
?>
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/949456.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/949456.htmlTechArticleTwo ways of php+mysqli database connection, mysqli database connection This article describes the two ways of php+mysqli database connection way. Share it with everyone for your reference. The details are as follows: Here...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn