How to connect to the database after mysqli extension is enabled in php

Source: Internet
Author: User
Mysqli is only available after php5. Friends who have not enabled the extension can open your php. ini configuration file. It has many new features and advantages over mysql. For more information, see

Mysqli is only available after php5. Friends who have not enabled the extension can open your php. ini configuration file. It has many new features and advantages over mysql. For more information, see

Mysqli is only available after php5. If you have not enabled the extension, you can open your php. ini configuration file.
Find the following statement:; extension = php_mysqli.dll and change it to extension = php_mysqli.dll.
Compared with mysql, mysql has many new features and advantages.
(1) Support local binding, preparation (prepare) and other syntaxes
(2) error code for executing SQL statements
(3) execute multiple SQL statements at the same time
(4) provides an object-oriented method for calling interfaces.
Next we will use a php instance to connect to the mysqli database!
Method 1: use traditional process-oriented methods
The php code is as follows:
The Code is as follows:
$ Connect = mysqli_connect ('localhost', 'root', '', 'volunteer') or die ('unale to connection ');
$ SQL = "select * from vol_msg ";
$ Result = mysqli_query ($ connect, $ SQL );
While ($ row = mysqli_fetch_row ($ result )){
Echo $ row [0];
}
?>

Method 2: Use an object-oriented method to call an interface (recommended)
The php code is as follows:
The Code is as follows:
// Create an object and open the connection. The last parameter is the selected database name.
$ Mysqli = new mysqli ('localhost', 'root', '', 'volunteer ');
// Check whether the connection is successful
If (mysqli_connect_errno ()){
// Note the new features of mysqli_connect_error ()
Die ('unable to connect! '). Mysqli_connect_error ();
}
$ SQL = "select * from vol_msg ";
// Execute SQL statements, fully object-oriented
$ Result = $ mysqli-> query ($ SQL );
While ($ row = $ result-> fetch_array ()){
Echo $ row [0];
}
?>

The running results of the above two php instances are identical. You can clearly see the advantages of using mysqli class objects to build database connections!
I don't need to talk about inserting and modifying records. Just change the SQL statement. In the next article, I will talk about the prepare interface features!

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.