首 页   · 站长博客 · 用户注册 · 会员登陆  · 会员排行  ·最新主题  ·最近回复  精华区  版权声明  ·论坛管理
  当前登录身份:游客,请先登录。  笔名: 口令: 验证码:   
楼 主  index »  PHP+MYSQL编程 » [转帖]简单介绍下 PHP5 中引入的 MYSQLI  


  作者:一起PHP
  注册时间:2004-02-27
  主题/回复:247/1521
  积分:4649
  等级:★★★★★☆(十一级)
  称号:论坛圣人

  nqp@nqp.me
  4304410
  www.nqp.me

 

 发表:2004-04-19 16:33:37 阅读 3601 次 回复 2 次 得分2  |   字号 字色
[转帖]简单介绍下 PHP5 中引入的 MYSQLI
作者:KnightE 来源:超越PHP 

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

mysqli.dll是PHP对mysql新特性的一个扩展支持。在PHP5中可以在php.ini中加载,如下图:
{{http://www.phpe.net/uploads/images/article_i_6235.gif}}
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-)
 
 1#楼  
 
  回复人:yunyang0601
  注册时间:2008-04-17
  主题/回复:0/3
  积分:27
  等级:★(二级)
  称号:初出茅庐

   
 1#楼 发表于2008-04-17 10:51:21  评分:1 

回复给楼主(一起PHP)
为了使大家更熟练的使用PHP做出各式各样的网站.以满足自己做站的需要.现广州PHP14期的PHP业余班培训班马上要开班了. 
学习的内容主要是:http://www.dodiphp.cn/edu_news_detail.php?id=388 看课程介绍 

培训地点是:广州市天河 

如果大家有兴趣.并且能实地来上课的话.不妨报个名.并且留个QQ或联系电话或直接加QQ799847297咨询
 2#楼  
 
  回复人:lurenjia
  注册时间:2009-08-23
  主题/回复:0/5
  积分:30
  等级:★(二级)
  称号:初出茅庐

   
 2#楼 发表于2009-08-23 00:21:45  评分:1 

回复给楼主(一起PHP)
http://www.phprm.com/
  页数1/1首页 « 1 » 末页
  发表回复:您还没有登陆,无法发表回复。请先[登陆]

一起PHP技术联盟 主办:一起PHP 联系方式:站长QQ:4304410 QQ群:8423742 20159565 站长博客 E-mail: nqp@nqp.me 执行时间:0.009sec
SimsmaBBS 2008 (v6.0) Developed by 17php.com,Copyright(C)2003-2010 All rights reserved. 副本授权:一起PHP官方专用版