php調(diào)用mysql存儲過程
更新時間:2007年02月14日 00:00:00 作者:
前面轉(zhuǎn)載了一篇《php調(diào)用mysql存儲過程的文章》經(jīng)過測試,發(fā)現(xiàn)文章中的方法似乎不可行!
調(diào)用帶有select語句的存儲過程就出現(xiàn) PROCEDURE p can't return a result set in the given context的錯誤。google了半天,在mysql官網(wǎng)上找到一些說法,db_mysql的模塊不支持存儲過程調(diào)用,解決方法是用db_mysqli。測試了一下,果然可以了。
用法比較簡單,沒啥好說的,從網(wǎng)上copy一段代碼吧:
<?php
/* Connect to a MySQL server */
$link = mysqli_connect(
'localhost', /* The host to connect to */
'root', /* The user to connect as */
'root', /* The password to use */
'db_name'); /* The default database to query */
if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
/* Send a query to the server */
if ($result = mysqli_query($link, "call se_proc('crm')")) {
/* Fetch the results of the query */
while( $row = mysqli_fetch_array($result) ){
echo ($row[0]. "--------- SR. " . $row[1] . "
");
}
/* Destroy the result set and free the memory used for it */
mysqli_free_result($result);
}
/* Close the connection */
mysqli_close($link);
?>
郁悶的是費了半天勁搞出來的存儲過程效率居然不如以前- -
調(diào)用帶有select語句的存儲過程就出現(xiàn) PROCEDURE p can't return a result set in the given context的錯誤。google了半天,在mysql官網(wǎng)上找到一些說法,db_mysql的模塊不支持存儲過程調(diào)用,解決方法是用db_mysqli。測試了一下,果然可以了。
用法比較簡單,沒啥好說的,從網(wǎng)上copy一段代碼吧:
<?php
/* Connect to a MySQL server */
$link = mysqli_connect(
'localhost', /* The host to connect to */
'root', /* The user to connect as */
'root', /* The password to use */
'db_name'); /* The default database to query */
if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
/* Send a query to the server */
if ($result = mysqli_query($link, "call se_proc('crm')")) {
/* Fetch the results of the query */
while( $row = mysqli_fetch_array($result) ){
echo ($row[0]. "--------- SR. " . $row[1] . "
");
}
/* Destroy the result set and free the memory used for it */
mysqli_free_result($result);
}
/* Close the connection */
mysqli_close($link);
?>
郁悶的是費了半天勁搞出來的存儲過程效率居然不如以前- -
您可能感興趣的文章:
相關(guān)文章
php中判斷數(shù)組相等的方法以及數(shù)組運算符介紹
這篇文章主要介紹了php中判斷數(shù)組相等的方法以及數(shù)組運算符介紹,本文講解了相關(guān)知識并給出實例代碼,需要的朋友可以參考下2015-03-03
解決wincache不支持64位PHP5.5/5.6的問題(提供64位wincache下載)
這篇文章主要解決wincache不支持64位PHP5.5/5.6的問題,并提供64位wincache的下載,需要的朋友可以參考下。2016-06-06
php實現(xiàn)的網(wǎng)頁版剪刀石頭布游戲示例
這篇文章主要介紹了php實現(xiàn)的網(wǎng)頁版剪刀石頭布游戲,涉及php數(shù)組遍歷、比較及隨機(jī)數(shù)組調(diào)用相關(guān)操作技巧,需要的朋友可以參考下2016-11-11
使用GROUP BY的時候如何統(tǒng)計記錄條數(shù) COUNT(*) DISTINCT
在有g(shù)roup by的時候,如何統(tǒng)計結(jié)果記錄的數(shù)量?需要的朋友可以參考下。2011-04-04

