简单介绍下 PHP5 中引入的 MYSQLI的用途
王蒙近况,摄录一体机,轻
在新下载的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-)
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
-
-
Yii框架应用组件用法实例分析
本文实例讲述了yii框架应用组件用法。分享给大家供大家参考,具体如下:应用组件 应用主体是, 它部署一组提供各种不同功能的 应用组件 来处理请求。 例如,url...
[阅读全文]
-
-
-
-
-
Yii 框架入口脚本示例分析
本文实例讲述了yii 框架入口脚本。分享给大家供大家参考,具体如下:入口脚本入口脚本是应用启动流程中的第一环, 一个应用(不管是网页应用还是控制台应用)只有一个...
[阅读全文]
-
PHP强制转化的形式整理
php强制转化有几种形式php强制转化有3种形式:1、在要转换的变量之前加上用括号括起来的目标类型;2、使用转强函数,如“intval()”,“strval()...
[阅读全文]
-
php7 新增功能实例总结
本文实例总结了php7 新增功能。分享给大家供大家参考,具体如下:一、核心 增加了group use语法声明。rfc: https://wiki.php.ne...
[阅读全文]
网友评论