视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
简单介绍下 PHP5 中引入的 MYSQLI的用途
2020-11-27 19:02:48 责编:小采
文档

在新下载的PHP5中你会发现多了一个mysqli.dll,它是干什么用的呢?我简单介绍下。。
mysqli.dll是PHP对mysql新特性的一个扩展支持。在PHP5中可以在php.ini中加载.
mysql后面的i,指improved, interface, ingenious, incompatible or incomplete(改扩展仍在开发中,因为MYSQL4。1和MYSQL5都没有正式推出尚在开发中,新的特性没有完全实现)
mysqli想实现的目标具体有:
-更简单的维护
-更好的兼容性
-向后兼容
mysql(指PHP中的模块)发展到现在显得比较凌乱,有必要重新做下整理。同时,有必要跟上MYSQL(DBMS)的发展步伐,加入新的特性的支持,以及适应MYSQL(DBMS)以后的版本。所以诞生了mysqli.dll
mysqli.dll的特性:
-可以和mysql.dll一样的方式使用
-支持OO接口,简简单单调用
-支持MYSQL4。1引入的新特性
-通过mysqli_init() 等相关函数,可以设置高级连接选项
mysqli的使用例子:
1.和以前mysql.dll一样的方法:
代码如下:
<?php 
/* 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);  
?>  

输出结果:
Very large cities are:
Mumbai (Bombay) (10500000)
Seoul (9981619)
São Paulo (9968485)
Shanghai (9696300)
Jakarta (9604900)
2.使用内置OO接口方式调用:
代码如下:
<?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();  
?>  

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

下载本文
显示全文
专题