This article describes the way PHP uses MySQL and mysqli to connect to the MySQL database. Share to everyone for your reference, specific as follows:
The code is simple, straight up.
<?php/** * @Author: HTL * @Description: Description///lower PHP default error level//Only show all errors except disabled//resolution because of PHP5.3 + The version is too high to cause a discard warning when using mysql_connect "Deprecated:mysql_connect (): The MySQL extension is deprecated and would be removed in the
Future:use mysqli or PDO instead "error_reporting (e_all ^ e_deprecated);
$db _host= "localhost";
$db _user= "root";
$db _passwd= "";
$db _name= "MySQL";
Echo ("<BR>---------------------------mysql_connect------------------------<BR><BR>");
$query = "Select Session_user (), Current_User (), now ();";
$conn = mysql_connect ($db _host, $db _user, $db _passwd);
if (! $conn) {die (' could not connect: '. Mysql_error ());
} mysql_select_db ($db _name, $conn);
$result = mysql_query ($query);
while ($row = Mysql_fetch_array ($result)) {var_dump ($row);
} mysql_close ($conn);
Echo ("<BR>---------------------------mysqli_connect------------------------<BR><BR>"); $conn = Mysqli_connect ($db _host, $db _user, $db _passwd, $db _name);
if (! $conn) {die (' could not connect: '. Mysqli_error ());
}//execute the query.
$result = Mysqli_query ($conn, $query);
Display Information:while ($row = Mysqli_fetch_array ($result)) {var_dump ($row);
} mysqli_close ($conn);
Exit ();?>
There's a picture of the truth.
More about PHP Interested readers can view the site topics: "PHP+MYSQLI Database Programming Skills Summary", "PHP based on PDO Operation Database Skills summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", " Introduction to PHP object-oriented programming, "PHP string (String) Usage Summary", "Php+mysql Database Operations Introduction Tutorial" and "PHP Common database Operation tips Summary"
I hope this article will help you with the PHP program design.