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_num_rows VS COUNT 效率问题分析

mysql_num_rows 和 count( * ) 都能统计总数,那个能好一点呢? 或者 分别什么时候用num_rows 和 count( * )呢 一个直观的对比 测试数据: 条数...

PHP7.0连接DB操作实例分析【基于mysqli】

PHP7.0连接DB操作实例分析【基于mysqli】

本文实例讲述了PHP7.0连接DB操作。分享给大家供大家参考,具体如下: PHP <?php //连接数据库 $link = mysqli_connect('local...

php mysql like 实现多关键词搜索的方法

或者叫,分词检索数据库 $res = mysql_query("select * from peter where id like '%中草药%' and '%6%'"); //这样写是...

一款简单实用的php操作mysql数据库类

本文实例讲述了一款简单实用的php操作mysql数据库类。分享给大家供大家参考。具体如下: 复制代码 代码如下: /* 本款数据库连接类,他会自动加载sql防注入功能,过滤一些敏感的s...

php+mysql实现数据库随机重排实例

本文实例实现了php+mysql数据库随机重排的方法,可将表中的所有数据随机读出来一次之后再进行随机保存到另一个表,从而达到了记录随机的功能。 主要实现代码如下: 复制代码 代码如下:&...