The difference between MySQL and mysqli in PHP

Source: Internet
Author: User
Tags mysql resource mysql database

One: Mysqli.dll is a way to manipulate the database in an object-or-process manner, and it is easy to use. Here is a comparison of several common operations with Mysql.dll.
1:mysql.dll (can be understood as a functional approach):

$conn = mysql_connect (' localhost ', ' user ', ' password '); Connecting to the MySQL database
mysql_select_db (' data_base '); Select Database
  
$result = mysql_query (' select * from Data_base ');//Here is a second optional parameter that specifies an open connection

$row = Mysql_fetch_row ($result))//For simplicity, only one row of data is taken here
echo $row [0]; Output the value of the first field

Mysqli also has a process-style approach, but it starts with a mysqli prefix, all the same. If Mysqli is manipulated in a procedural way, some functions must specify resources, such as mysqli_query (resource identification, SQL statement), and resource identifier parameters are placed in front, while mysql_query (SQL statement, ' optional ') resource identification is placed behind , and can be unspecified, which defaults to the last open connection or resource.

2mysqli.dll (object mode):

$conn = new mysqli (' localhost ', ' user ', ' password ', ' data_base ');
The connection here is new, and the last parameter is to specify the database directly, without mysql_select_db ().
can also be constructed without specifying, and then $conn-> select_db (' data_base ')

$result = $conn-> query (' SELECT * from Data_base ');
$row = $result-> fetch_row (); Fetch a row of data
Echo Row[0]; Output the value of the first field

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.