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

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

相关文章

整理的一些实用WordPress后台MySQL操作命令

不过假设你的WordPress网站上有成百上千篇文章,而你需要进行全站范围的改动, 这时从后台逐条编辑就有点费时费力了,并且犯错的几率也会提高。 最好的方法是进入WordPress的My...

攻克CakePHP系列一 连接MySQL数据库

攻克CakePHP系列一 连接MySQL数据库

先阅读这个https://www.jb51.net/article/16244.htm接下来将一步一步对这个框架进行说明。 首先是下载框架:官方主页:http://cakephp.org...

支持php4、php5的mysql数据库操作类

前端一直使用PHP5,的确使用起来特别的爽,现在为了能在俺的虚拟主机上跑,不得不改成PHP4的。这几个库类我以前发在PHPCHIAN,地址是http://www.phpchina.com...

php实现Mysql简易操作类

自己封装的Mysql简易操作类,已塞在Ben框架中,基于PDO来写的,代码风格上有些无厘头。。。 mysql.class.php <?php class mysql e...

php实现mysql同步的实现方法

拿到需求之后,发现这两个网站的MYSQL数据库都不能远程访问(安全第一吧)。于是想起了 平时使用的CSV文件批量录入数据。于是 尝试使用CSV导入导出。 导入到处框架如下: 1首先将数据...