简单介绍下 PHP5 中引入的 MYSQLI
2013-09-04 21:40
453 查看
在新下载的PHP5中你会发现多了一个mysqli.dll,它是干什么用的呢?我简单介绍下:
mysqli.dll是PHP对mysql新特性的一个扩展支持。在PHP5中可以在php.ini中加载,如下图:
, 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一样的方法:
/* 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接口方式调用:
/* 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等。
mysqli.dll是PHP对mysql新特性的一个扩展支持。在PHP5中可以在php.ini中加载,如下图:
, 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一样的方法:
/* 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接口方式调用:
/* 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等。
相关文章推荐
- 简单介绍下 PHP5 中引入的 MYSQLI的用途
- 简单介绍下 PHP5 中引入的 MYSQLI的用途
- php5的简单介绍
- Android Studio引入Lambda以及介绍和简单实用
- python import 引入简单介绍
- mysqli与mysql_result类的简单介绍与小实例
- 创建一个Storyboard工程 storyboard是在ios5中引入的新控件,能够更加清晰、简单的整合多个ViewController的关系,下面主要介绍一下怎么初建一个storyboard的工程
- 基于注解的Spring MVC简单介绍)
- Retrofit的使用,及介绍,Retrofit中的各种方法的详细描述简单案例,三分钟学会Retrofit
- lombok的简单介绍(2)
- Allway Sync--同步备份数据资料,简单介绍及使用经验分享
- 密码学简单介绍
- 分布式--简单介绍分布式算法
- oracle sql_trace 简单应用介绍
- 简单记录:几个MySQL引擎简单介绍
- ANT简单介绍
- fflush(stdout)用处简单介绍
- shell语法简单介绍
- Maven 简单介绍
- 计算机网络实验,JAVA实现一个简单GBN协议,模拟引入数据包的丢失,验证协议的有效性