php调用mysql存储过程

yipeiwu_com6年前Mysql基础
前面转载了一篇《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);
?>

郁闷的是费了半天劲搞出来的存储过程效率居然不如以前- -

相关文章

PHP+mysql实现从数据库获取下拉树功能示例

本文实例讲述了PHP+mysql实现从数据库获取下拉树功能。分享给大家供大家参考,具体如下: <?php include "config.php"; include "...

小结下MySQL中文乱码,phpmyadmin乱码,php乱码 产生原因及其解决方法第1/3页

乱码产生原因  mysql字符编码是版本4.1引入的,支持多国语言,而且一些特性已经超过了其他的数据库系统。 我们可以在MySQL Command Line...

php+mysql实现无限级分类

项目思路分析:一个PHP项目要用到分类,但不确定分几级,所以就想做成无限级分类。 一开始想是按以前一样,数据库建4个值,如下: id: 自增   | &nb...

mysql时区问题

用convert_tz转换时区,你可以用      show   variables  ...

PHP使用PDO从mysql读取大量数据处理详解

前言 本文主要介绍了关于PHP利用PDO从mysql读取大量数据处理的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。 环境 mysql: 5.6.34...