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一样的方法:
<?
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等。。。