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);
?>

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

相关文章

Mac OS下配置PHP+MySql环境

Mac OS下配置PHP+MySql环境

由于最近需要布置mantis用来进行bug追踪,在此记录其过程。 由于PHP apache环境在Mac OS上是自带的,所以不需要另处下安装包,只需要简单配置一下即可。 首先打开终端输入...

PHP结合Redis+MySQL实现冷热数据交换应用案例详解

PHP结合Redis+MySQL实现冷热数据交换应用案例详解

本文实例讲述了PHP结合Redis+MySQL实现冷热数据交换应用案例。分享给大家供大家参考,具体如下: 场景:某网站需要对其项目做一个投票系统,投票项目上线后一小时之内预计有100万...

mysql5的sql文件导入到mysql4的方法

1、将mysql5里导出的sql文件导入到mysql5中。 2、用mysqldump -uroot -p1234 --opt --compatible=mysql40 -A -re:\l...

php连接mysql数据库

连接数据库: 使用面向对象的方法; 1.造一个mysqli对象,造连接对象 2.准备一条SQL语句 3.执行SQL语句,如果是查询语句。成功返回结果及对象 4.从结果集对象里找到数据;...

MySQL授权问题总结

我用localhost的root帐号不能连 最后请教DBA组新建用户搞定! 现弄些受权用户的资料 以备不时之需 授权表使用举例 grant用于给增加用户和创建权限,r...