网站首页 工具软件 操作系统 办公软件 网页制作 PHP教程 script脚本专栏 photoshop教程 其他精品教程
我发布的文章 - 教程搜索 - 交流论坛 - 帮助中心 - 网站首页 网络工具 - 常用工具 - 媒体工具 - 系统工具 - 实用工具 NT/2003 - Win Xp - Win2000 - DOS/Win9x - IE/注册表 - Linux - 苹 果 Office - Word - Excel - PowerPoint - 输入法 - 邮件处理 Flash - Dreamweaver - Fireworks - FrontPage - HTMLCSS 基础文章 - PHP函数 - PHP技巧 - 数据库相关 - 高级应用 - PHP安装 - 转载精华 - 常见问题 综 合 类 - 状 态 栏 - 游 戏 类 - 页面背景 - 页面特效 - 页面导航 - 文本操作 - 文本特效 - 图形特效 - 鼠标特效 - 时间日期 - 密 码 类 文字特效 - 按钮与图标 - 色彩运用 - 滤镜魔法 - 综合实例 XML教程 - DELPHI基础教程 - VB教程
首页 -> PHP教程 -> 数据库相关

TOP

简单介绍下 PHP5 中引入的 MYSQLI
文章内容
相关信息
用户评论
文章内容
在新下载的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 */ 
$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(); 
?> 


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

注:感觉这个不是对所有人都有用。不过。。。相信可以帮助大家多了解些“变化”,能更好的把握“趋势” 8-)



相关信息
简单介绍下 PHP5 中引入的 MYSQLI
发布者:mmcbbs
浏览量:173
发布日期:2005-04-10 01:20:47
所属专题:
用户评论
称  呼:
内  容:

广告位

广告招租,欢迎抢订

热门信息

·MySQL用户管理
·SQL语言快速入门(一)
·SQL语言快速入门(二)
·SQL语言快速入门(三)
·数据库设计技巧(三)
·从 MySQL 导入导出大量数据..
·MySQL安全性指南
·PHP中通过ADO调用Access数据库

推荐信息