Home > Backend Development > PHP Tutorial > php calls mysql stored procedure_PHP tutorial

php calls mysql stored procedure_PHP tutorial

WBOY
Release: 2016-07-21 15:57:06
Original
878 people have browsed it

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 - -

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317909.htmlTechArticleAn article on "php calling mysql stored procedures" was reprinted earlier. After testing, it was found that the method in the article seemed not to work. OK! PROCEDUREpcan appears when calling a stored procedure with a select statement...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template