Home >Backend Development >PHP Tutorial >h5 briefly introduces the use of MYSQLI introduced in PHP5

h5 briefly introduces the use of MYSQLI introduced in PHP5

WBOY
WBOYOriginal
2016-07-29 08:36:44791browse

In the newly downloaded PHP5, you will find an extra mysqli.dll. What is it used for? Let me briefly introduce it. . .
mysqli.dll is PHP’s extended support for new mysql features. In PHP5, it can be loaded in php.ini.
The i after mysql refers to improved, interface, ingenious, incompatible or incomplete (the extension is still under development, because neither MYSQL4.1 nor MYSQL5 has been officially launched and is still under development. New features have not been fully implemented)
The specific goals that mysqli wants to achieve are:
-Easier maintenance
-Better compatibility
-Backwards compatibility
Mysql (referring to modules in PHP) has developed to the point where it seems messy. It is necessary to reorganize it. At the same time, it is necessary to keep up with the development pace of MYSQL (DBMS), add support for new features, and adapt to future versions of MYSQL (DBMS). So mysqli.dll was born
Features of mysqli.dll:
-Can be used in the same way as mysql.dll
-Supports OO interface, simple call
-Supports new features introduced by MYSQL4.1
-Through mysqli_init() and other related functions, you can set advanced connection options
Mysqli usage example:
1. The same method as before mysql.dll:

Copy the code The code is as follows:


/* Connect to a MySQL server */
$link = mysqli_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 results:
Very large cities are:

Mumbai (Bombay) (10500000)
Seoul (9981619)
São Paulo (9968485)
Shanghai (9696 300)
Jakarta (9604900)
2. Use Built-in OO interface call:



Copy code

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();  
?>  


支持的新特性还有:Bound Parameters,Bound Results等。。。
有兴趣的可以直接去参看原英文:
http://www.zend.com/php5/articles/php5-mysqli.php#fn3
注:感觉这个不是对所有人都有用。不过。。。相信可以帮助大家多了解些“变化”,能更好的把握“趋势” 8-) 

以上就介绍了h5 简单介绍下 PHP5 中引入的 MYSQLI的用途,包括了h5方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn