Home >Backend Development >PHP Tutorial >php calls mysql stored procedure_PHP tutorial
I reprinted an article earlier called "php calls mysql stored procedure". After testing, I found that the method in the article seems not feasible!
When calling a stored procedure with a select statement, the error "PROCEDURE p can't return a result set in the given context" occurs. After googling for a long time, I found some statements on the mysql official website. The db_mysql module does not support stored procedure calls. The solution is to use db_mysqli. I tested it and it works.
The usage is relatively simple, there is nothing to say, just copy a piece of code from the Internet:
/* 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: %sn", 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);
?>
What is depressing is that the stored procedure that took a long time to come up with is not as efficient as before - -