Home > Article > Backend Development > PHP calls stored procedure to return result set
php calls a stored procedure to return a result set, and the method to solve the error of can't return a result set in the given context
requires php to call a stored procedure and return a result set. I found it very difficult. After searching for a long time, I finally found it on the foreigner's forum Found the solution on the website, localize it here.
The key is mysql_connect, add 1,131072 to the fourth parameter
$link = mysql_connect("127.0.0.1", "root", "",1,131072) or die("Could not connect: ".mysql_error ());
The following can be used normally. The following is an example program.
<?php define('CLIENT_MULTI_RESULTS', 131072); $link = mysql_connect("127.0.0.1", "root", "",1,CLIENT_MULTI_RESULTS) or die("Could not connect: ".mysql_error()); mysql_select_db("vs") or die("Could not select database");?>
<?php $result = mysql_query("call get_news_from_class_id(2)") or die("Query failed:" .mysql_error()); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $line = '<tr><td><a target = _blank href=\''.$row["url"].'\'>'.$row["title"].'('.$row["page_time"].')'.'</a></td></tr>'; echo $line; printf("\n"); } mysql_free_result($result); ?>
<?php mysql_close($link); ?>