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 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:
Copy codeThe Code is as follows:
<? Php
/* 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:
Copy codeThe Code is as follows:
<? Php
/* 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 -)