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连接字符集的方法

mysql_set_charset()。 这个函数是这样用的: mysql_set_charset('utf8', $link); 成功返回 TRUE,失败返回 FALSE。 就这么简单...

php+mysql+ajax实现单表多字段多关键词查询的方法

php+mysql+ajax实现单表多字段多关键词查询的方法

本文实例讲述了php+mysql+ajax实现单表多字段多关键词查询的方法。分享给大家供大家参考,具体如下: 单表多字段查询在一些稍微复杂一点的查询中十分有用。这里主要利用MySQL数据...

PHP读MYSQL中文乱码的快速解决方法

打算切换某个网站的主机,没想到遇到Php和Mysql中文乱码的问题。 以前的国外主机用的Mysql是4.x系列的,感觉还比较好,都无论GBK和UTF-8都没有乱码,没想到新的主机的Mys...

实战mysql导出中文乱码及phpmyadmin导入中文乱码的解决方法

实战mysql导出中文乱码及phpmyadmin导入中文乱码的解决方法

一直不用这个phpmyadmin,在本机也是用navicat,总感觉phpmyadmin速度较慢。这回不行了,没有独立主机,只好用人家给的phpmyadmin了。 第一步:本地数据导出s...

mysql时区问题

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