PHP uses mysql and mysqli to connect to Mysql database usage example, mysqlimysql

Source: Internet
Author: User
Tags deprecated php error

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.