Home  >  Article  >  Backend Development  >  A brief introduction to the use of MYSQLI introduced in PHP5_PHP Tutorial

A brief introduction to the use of MYSQLI introduced in PHP5_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:56:11896browse

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 mysqli wants to achieve are:
-Easier maintenance
-Better compatibility
-Backward compatibility
mysql (referring to Modules in PHP) have developed into a messy situation now, and 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, simply call
- Supports MYSQL4.1 introduced New features
- Advanced connection options can be set through mysqli_init() and other related functions
Examples of mysqli usage:
1. The same method as the previous mysql.dll:

Copy code The code is as follows:

/* Connect to a MySQL server */
$link = mysqli_connect(
'localhost', /* The host to connect to */
'user', /* The user to connect as */
'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 built-in OO Interface method 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-) 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/318085.htmlTechArticle在新下载的PHP5中你会发现多了一个mysqli.dll,它是干什么用的呢?我简单介绍下。。。 mysqli.dll是PHP对mysql新特性的一个扩展支持。在PHP5中可...
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