Home  >  Article  >  Backend Development  >  php calls mysql stored procedure

php calls mysql stored procedure

WBOY
WBOYOriginal
2016-07-29 08:36:21998browse

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’s frustrating is that the stored procedure that took a long time to come up with is not as efficient as before - -

The above introduces how PHP calls mysql stored procedures, including aspects of the process. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn