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);
?>
郁悶的是費了半天勁搞出來的存儲過程效率居然不如以前- -
您可能感興趣的文章:
相關文章
騰訊微博提示missing parameter errorcode 102 錯誤的解決方法
這篇文章主要介紹了騰訊微博提示missing parameter errorcode 102 錯誤的解決方法,是針對騰訊微博接口開發(fā)中比較典型的錯誤問題,需要的朋友可以參考下2014-12-12php5.3提示Function ereg() is deprecated Error問題解決方法
這篇文章主要介紹了php5.3提示Function ereg() is deprecated Error問題解決方法,主要是由于php5.3對ereg()函數(shù)升級造成的,使用時只要對其規(guī)則和函數(shù)進行簡單的修改即可,需要的朋友可以參考下2014-11-11