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

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

相关文章

mysql时区问题

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

mysql 查询指定日期时间内sql语句实现原理与代码

在数据库教程设计时必须注意时间字段为int(11)这样,保存在数据库的是一个数字型日期时间戳,我们可以用mktime函数求出当前日期的时间戳进行加减就OK了,下面看实例 //一个月 复制...

PHP获取MySQL执行sql语句的查询时间方法

如下所示: //计时开始 runtime(); //执行查询 mysql_query($sql); //计时结束. echo runtime(1); //计时函数 fu...

PHP开发者常犯的10个MySQL错误更正剖析

1.使用MyISAM而不是InnoDB   完全错误,反驳理由:   首先原文说MyISAM是默认使用的,而实际上到了MySQL 5.5.x,InnoDB已经成为了默认的表引擎。   另...

PHP5.5基于mysqli连接MySQL数据库和读取数据操作实例详解

本文实例讲述了PHP5.5基于mysqli连接MySQL数据库和读取数据操作。分享给大家供大家参考,具体如下: 在学习1. 开启PHP的API支持 (1)首先修改您的php.ini的配置...