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扩展” 的解决方法

访问phpmyadmin时总是出现 “无法载入 mysql 扩展,请检查 PHP 配置”。查看原因是“php_mysql.dll”无法载...

fetchAll()与mysql_fetch_array()的区别详解

同一个查询语句:fetchAll():复制代码 代码如下:array(1) {          ...

PHP+MySql+jQuery实现的"顶"和"踩"投票功能

本文实例为大家分享了基于PHP+jQuery+MySql实现红蓝(顶踩)投票代码,供大家参考,具体内容如下 数据库操作: CREATE TABLE IF NOT EXISTS `vo...

php判断输入不超过mysql的varchar字段的长度范围

但是如果在utf-8编码下,一个汉字是占3个字符长度的,比如字符串$str=”你好啊!!”; 如果你用strlen函数来判断,长度是11,正好超过了varchar的长度,但实际上确不是这...

php 无法加载mysql的module的时候的配置的解决方案引发的思考

php 无法加载mysql的module的时候的配置的解决方案引发的思考

之后看phpinfo() 里 确实也没找到mysql 模块, 之后所谓的解决方案如“将php.ini” 放入C:\Windows 环境变量等不靠谱说法。。。。。 甚至拷贝ext的文件夹的...