简单介绍下 PHP5 中引入的 MYSQLI的用途
2015-01-24信息快讯网
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-)
php 攻击方法之谈php+mysql注射语句构造
PHP 文件上传源码分析(RFC1867)
浅谈PHP 闭包特性在实际应用中的问题
php实现jQuery扩展函数
PHP 读取和修改大文件的某行内容的代码
php实现mysql同步的实现方法
用mysql触发器自动更新memcache的实现代码
使用zend studio for eclipse不能激活代码提示功能的解决办法
PHP5 操作MySQL数据库基础代码
从Web查询数据库之PHP与MySQL篇
通过PHP CLI实现简单的数据库实时监控调度
php split汉字
PHP SQLite类
linux php mysql数据库备份实现代码
关于在php.ini中添加extension=php_mysqli.dll指令的说明
php分页示例代码
IIS6的PHP最佳配置方法
php中的实现trim函数代码
php中判断一个字符串包含另一个字符串的方法
php之字符串变相相减的代码
PHP入门速成教程
PHP_MySQL教程-第三天 基本函数第1/2页
PHP_MySQL教程-第二天while循环与数据库操作第1/2页
PHP_MySQL教程-第一天
php环境配置 php5 MySQL5 apache2 phpmyadmin安装与配置图文教程
Linux下进行MYSQL编程时插入中文乱码的解决方案
mysql4.1以上版本连接时出现Client does not support authentication protocol问题解决办法
再次研究下cache_lite
cache_lite试用
mysql 的 like 问题,超强毕杀记!!!