Brief introduction to the usage of MYSQLI introduced in PHP5 _ PHP Tutorial

Source: Internet
Author: User
This section briefly introduces the usage of MYSQLI introduced in PHP5. In the newly downloaded PHP5, you will find an additional mysqli. dll. what is it? Let me briefly introduce... Mysqli. dll is an extension of PHP to mysql's new features. In PHP5, you can find an additional mysqli. dll in the newly downloaded PHP5. what is it? Let me briefly introduce...
Mysqli. dll is an extension of PHP to mysql's new features. In PHP5, you can load.
I after mysql refers to improved, interface, ingenious, incompatible or incomplete (the extension is still under development because mysql4. 1. Neither MYSQL5 nor MYSQL5 has been officially launched yet. new features are not fully implemented)
The specific objectives of mysqli are as follows:
-Simpler maintenance
-Better compatibility
-Backward compatibility
Mysql (a module in PHP) has become messy and needs to be reorganized. At the same time, it is necessary to keep up with the development of MYSQL (DBMS), add support for new features, and adapt to versions later than MYSQL (DBMS. So mysqli. dll was born.
Features of mysqli. dll:
-It can be used in the same way as mysql. dll.
-Supports OO interfaces, which can be called simply
-MySQL 4 is supported. 1. new features introduced
-You can set Advanced connection options through related functions such as mysqli_init ().
Example of mysqli:
1. the same method as mysql. dll:

The code is as follows:


/* Connect to a MySQL server */
$ Link = mysqli_connect (
'Localhost',/* The host to connect */
'User',/* The user to connect */
'Password',/* The password to use */
'World');/* The default table to query */
If (! $ Link ){
Printf ("Can't connect to MySQL Server. Errorcode: % sn", mysqli_connect_error ());
Exit;
}
/* Send a query to the server */
If ($ result = mysqli_query ($ link, 'Select Name, Population FROM City order by Population desc limit 5 ')){
Print ("Very large cities are: n ");
/* Fetch the results of the query */
While ($ row = mysqli_fetch_assoc ($ result )){
Printf ("% s (% s) n", $ row ['name'], $ row ['population']);
}
/* Destroy the result set and free the memory used for it */
Mysqli_free_result ($ result );
}
/* Close the connection */
Mysqli_close ($ link );
?>


Output result:
Very large cities are:
Mumbai (Bombay) (10500000)
Seoul (9981619)
S ã o Paulo (9968485)
Shanghai (9696300)
Jakarta (9604900)
2. use the built-in OO interface to call:

The code is as follows:


/* Connect to a MySQL server */
$ Mysqli = new mysqli ('localhost', 'user', 'password', 'World ');
If (mysqli_connect_errno ()){
Printf ("Can't connect to MySQL Server. Errorcode: % sn", mysqli_connect_error ());
Exit;
}
/* Send a query to the server */
If ($ result = $ mysqli-> query ('select Name, Population FROM City order by Population desc limit 5 ')){
Print ("Very large cities are: n ");
/* Fetch the results of the query */
While ($ row = $ result-> fetch_assoc ()){
Printf ("% s (% s) n", $ row ['name'], $ row ['population']);
}
/* Destroy the result set and free the memory used for it */
$ Result-> close ();
}
/* Close the connection */
$ Mysqli-> close ();
?>


Supported new features include Bound Parameters and Bound Results...
If you are interested, please refer to the original English:
Http://www.zend.com/php5/articles/php5-mysqli.php#fn3
Note: I feel that this is not useful to everyone. But... I believe this will help you learn more about "changes" and better grasp the "trends" 8 -)

Why? Let me briefly introduce... Mysqli. dll is an extension of PHP to mysql's new features. In PHP5, you can...

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.