动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   PHP → 阅读文章

 简单介绍下 PHP5 中引入的 MYSQLI

作者来源: 
阅读 2507 人次 , 2006-3-29 4:18:00 


在新下载的php5中你会发现多了一个mysqli.dll,它是干什么用的呢?我简单介绍下。。。

mysqli.dll是php对mysql新特性的一个扩展支持。在php5中可以在php.ini中加载,如下图:

click to fullsize


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 */
上一篇      目录      下一篇 = 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 (!上一篇      目录      下一篇) {
printf(&quot;can't connect to mysql server. errorcode: %sn&quot;, 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(&quot;very large cities are:n&quot;);

/* fetch the results of the query */
while( $row = mysqli_fetch_assoc($result) ){
printf(&quot;%s (%s)n&quot;, $row['name'], $row['population']);
}

/* destroy the result set and free the memory used for it */
mysqli_free_result($result);
}

/* close the connection */
mysqli_close(上一篇      目录      下一篇);
?>



输出结果:
very large cities are:

mumbai (bombay) (10500000)
seoul (9981619)
s&atilde;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(&quot;can't connect to mysql server. errorcode: %sn&quot;, 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(&quot;very large cities are:n&quot;);

/* fetch the results of the query */
while( $row = $result->fetch_assoc() ){
printf(&quot;%s (%s)n&quot;, $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-)

 本文Tagsmysql  数据库  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:PHP数据库开发知多少
· 下一篇:PEAR MDB数据库抽象层一次编写—随处运行
· 树型论坛递归加速
· PHP.MVC的模板标签系统之初识PHP.MVC
· MySQL数据导入与导出
· 介绍几个array库的新函数
· PHP 编码规范(25)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077