查看: 7086|回复: 0
打印 上一主题 下一主题

简单介绍下 PHP5 中引入的 MYSQLI

[复制链接]
跳转到指定楼层
1#
发表于 2007-9-29 21:56:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
在新下载的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: %s\n", 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&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("Can't connect to MySQL Server. Errorcode: %s\n", 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();
?>

用户评论意见之一.仅做参考.....
/////////////////////////////////////////////////////////////////////////////////////////////////
// php.ini

enable_dl=1
extension_dir =c:apachephp_lib
extension=php_mysql.dll
extension=php_mysqli.dll

然后把php_mysql.dll和php_mysqli.dll复制到c:apachephp_lib
///////////////////////////////////////////////////////////////////////////////////////////////

支持的新特性还有:Bound Parameters,Bound Results等。。。
有兴趣的可以直接去参看原英文:
http://www.zend.com/php5/articles/php5-mysqli.php#fn3

注:感觉这个不是对所有人都有用。不过。。。相信可以帮助大家多了解些“变化”,能更好的把握“趋势” 8-)
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州朗动科技(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:政企网站,系统平台,微信公众号,各类小程序,手机APP客户端,浙里办微应用,浙政钉微应用、主机域名、虚拟空间、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2026 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

快速回复 返回顶部 返回列表