簡單介紹下 PHP5 中引入的 MYSQLI的用途
更新時(shí)間:2007年03月19日 00:00:00 作者:
在新下載的PHP5中你會(huì)發(fā)現(xiàn)多了一個(gè)mysqli.dll,它是干什么用的呢?我簡單介紹下。。。
mysqli.dll是PHP對(duì)mysql新特性的一個(gè)擴(kuò)展支持。在PHP5中可以在php.ini中加載.
mysql后面的i,指improved, interface, ingenious, incompatible or incomplete(改擴(kuò)展仍在開發(fā)中,因?yàn)镸YSQL4。1和MYSQL5都沒有正式推出尚在開發(fā)中,新的特性沒有完全實(shí)現(xiàn))
mysqli想實(shí)現(xiàn)的目標(biāo)具體有:
-更簡單的維護(hù)
-更好的兼容性
-向后兼容
mysql(指PHP中的模塊)發(fā)展到現(xiàn)在顯得比較凌亂,有必要重新做下整理。同時(shí),有必要跟上MYSQL(DBMS)的發(fā)展步伐,加入新的特性的支持,以及適應(yīng)MYSQL(DBMS)以后的版本。所以誕生了mysqli.dll
mysqli.dll的特性:
-可以和mysql.dll一樣的方式使用
-支持OO接口,簡簡單單調(diào)用
-支持MYSQL4。1引入的新特性
-通過mysqli_init() 等相關(guān)函數(shù),可以設(shè)置高級(jí)連接選項(xiàng)
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);
?>
輸出結(jié)果:
Very large cities are:
Mumbai (Bombay) (10500000)
Seoul (9981619)
São Paulo (9968485)
Shanghai (9696300)
Jakarta (9604900)
2.使用內(nèi)置OO接口方式調(diào)用:
<?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
注:感覺這個(gè)不是對(duì)所有人都有用。不過。。。相信可以幫助大家多了解些“變化”,能更好的把握“趨勢” 8-)
mysqli.dll是PHP對(duì)mysql新特性的一個(gè)擴(kuò)展支持。在PHP5中可以在php.ini中加載.
mysql后面的i,指improved, interface, ingenious, incompatible or incomplete(改擴(kuò)展仍在開發(fā)中,因?yàn)镸YSQL4。1和MYSQL5都沒有正式推出尚在開發(fā)中,新的特性沒有完全實(shí)現(xiàn))
mysqli想實(shí)現(xiàn)的目標(biāo)具體有:
-更簡單的維護(hù)
-更好的兼容性
-向后兼容
mysql(指PHP中的模塊)發(fā)展到現(xiàn)在顯得比較凌亂,有必要重新做下整理。同時(shí),有必要跟上MYSQL(DBMS)的發(fā)展步伐,加入新的特性的支持,以及適應(yīng)MYSQL(DBMS)以后的版本。所以誕生了mysqli.dll
mysqli.dll的特性:
-可以和mysql.dll一樣的方式使用
-支持OO接口,簡簡單單調(diào)用
-支持MYSQL4。1引入的新特性
-通過mysqli_init() 等相關(guān)函數(shù),可以設(shè)置高級(jí)連接選項(xiàng)
mysqli的使用例子:
1.和以前mysql.dll一樣的方法:
復(fù)制代碼 代碼如下:
<?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);
?>
輸出結(jié)果:
Very large cities are:
Mumbai (Bombay) (10500000)
Seoul (9981619)
São Paulo (9968485)
Shanghai (9696300)
Jakarta (9604900)
2.使用內(nèi)置OO接口方式調(diào)用:
復(fù)制代碼 代碼如下:
<?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
注:感覺這個(gè)不是對(duì)所有人都有用。不過。。。相信可以幫助大家多了解些“變化”,能更好的把握“趨勢” 8-)
您可能感興趣的文章:
- PHP mysql與mysqli事務(wù)使用說明 分享
- 解析在PHP中使用mysqli擴(kuò)展庫對(duì)mysql的操作
- 淺談php中mysql與mysqli的區(qū)別分析
- 解決phpmyadmin中缺少mysqli擴(kuò)展問題的方法
- PHP mysqli 增強(qiáng) 批量執(zhí)行sql 語句的實(shí)現(xiàn)代碼
- PHP mysqli擴(kuò)展庫 預(yù)處理技術(shù)的使用分析
- php中選擇什么接口(mysql、mysqli)訪問mysql
- php開啟mysqli擴(kuò)展之后如何連接數(shù)據(jù)庫
- PHP5 mysqli的prepare準(zhǔn)備語句使用說明
- php寫的帶緩存數(shù)據(jù)功能的mysqli類
- PHP Warning: PHP Startup: Unable to load dynamic library \ D:/php5/ext/php_mysqli.dll\
- php中關(guān)于mysqli和mysql區(qū)別的一些知識(shí)點(diǎn)分析
- 關(guān)于在php.ini中添加extension=php_mysqli.dll指令的說明
- php操作mysqli(示例代碼)
相關(guān)文章
PHP 第二節(jié) 數(shù)據(jù)類型之?dāng)?shù)值型
編程語言的兩大功能是數(shù)據(jù)處理和流程控制;數(shù)據(jù)處理的基礎(chǔ)是數(shù)據(jù)類型和數(shù)據(jù)接口;流程控制是各種控制語句;程序的組織協(xié)調(diào)是各種編程范式;這一節(jié)先看下PHP有哪些基本的數(shù)據(jù)類型2012-04-04一個(gè)阿拉伯?dāng)?shù)字轉(zhuǎn)中文數(shù)字的函數(shù)
一個(gè)阿拉伯?dāng)?shù)字轉(zhuǎn)中文數(shù)字的函數(shù)...2006-10-10