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来实现分页。那么我们首要的任务就是搭建PHP的工作环境。 环境准备 使用PHP技术,最好的搭档就是AMP(Apache,MySQL...

PHP Mysqli 常用代码集合

PHP5.0开始,不仅可以使用早期的mysql数据库扩展函数,还能使用新扩展的mysqli技术实现与mysql数据库的信息交流,PHP的mysqli扩展被封装在在一个类中,它是一种面向对...

使用 MySQL 开始 PHP 会话

默认情况下,PHP会话(session)是通过文件来保存的。这样做有以下几个缺点:     会话文件一般都很小,但文件数却很多,在文件系统中保存许...

windows下配置apache+php+mysql时出现问题的处理方法

windows: 安装apache,php,mysql 遇到的各种问题: 1. test.php运行不起,发现是httpd.conf中忘加AddType application/x-ht...

php+MySQL实现登录时验证登录名和密码是否正确

php+MySQL实现登录时验证登录名和密码是否正确

直入主题,先看php校验登录名和密码是否正确的代码: <?php $servername = "服务器名"; $username = "账户名"; $passw...