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乱码,用set names XXX解决的原理分享

先说MySQL的字符集问题。Windows下可通过修改my.ini内的 PHP代码 复制代码 代码如下: [mysql] default-character-set=utf8 //客户端...

Win2003下IIS+PHP+MySQL+Zend配置步骤详解第1/2页

一、软件的获取 1.php首先去http://www.php.net/downloads.php下载最新的PHP 5.2.0版本。 2.MySQL可以在http://dev.m...

php中转义mysql语句的实现代码

你总不可能对每一个这样的特殊字符都人工进行转义,何况你通常处理的都是表单自动提交的内容。 所以,应该使用mysql_real_escape_string函数: mysql_real_es...

php更新mysql后获取改变行数的方法

本文实例讲述了php更新mysql后获取改变行数的方法。分享给大家供大家参考。具体分析如下: 一个php更新mysql后获取改变的行数,在php中提供mysql函数来获取最后执行查询所影...

PHP mysqli事务操作常用方法分析

本文实例讲述了PHP mysqli事务操作常用方法。分享给大家供大家参考,具体如下: 1、 //打开(true)或关闭(false)本次数据库连接的自动命令提交事务模式 //参数如果...