PHP uses mysql and mysqli to connect to Mysql database usage example, mysqlimysql
This example describes how to connect PHP to a mysql database using Mysql and mysqli. We will share this with you for your reference. The details are as follows:
The code is simple and straightforward.
<? Php/*** @ Author: HTL * @ Description: description * // reduce the default PHP error level // only display all the errors except disabled // solve the "discard warning" error when using mysql_connect due to the high PHP5.3 + version deprecated: mysql_connect (): The mysql extension is deprecated and will 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> "); $ 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> export mysqli_connect ---------------------- <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 () ;?>
Images and truth