PHP uses MySQL and mysqli to connect MySQL database usage example _php tips

Source: Internet
Author: User
Tags deprecated

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.

Related Article

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.