前面轉載了一篇《php調用mysql預存程序的文章》經過測試,發現文章中的方法似乎不可行!
調用帶有select語句的預存程序就出現 PROCEDURE p can't return a result set in the given context的錯誤。google了半天,在mysql官網上找到一些說法,db_mysql的模組不支援預存程序調用,解決方案是用db_mysqli。測試了一下,果然可以了。
用法比較簡單,沒啥好說的,從網上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);
?>
鬱悶的是費了半天勁搞出來的預存程序效率居然不如以前- -