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查询结果中文显示乱码解决方法

我们首先假设数据库中采用的编码为UTF-8这时我们在PHP页面中应当首先添加复制代码 代码如下:<meta http-equiv="Content-Type" content="t...

PHP商品秒杀问题解决方案实例详解【mysql与redis】

本文实例讲述了PHP商品秒杀问题解决方案。分享给大家供大家参考,具体如下: 引言 假设num是存储在数据库中的字段,保存了被秒杀产品的剩余数量。 if($num > 0){...

PHP错误Warning:mysql_query()解决方法

php提示错误:Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localho...

php导入大量数据到mysql性能优化技巧

本文实例讲述了php导入大量数据到mysql性能优化技巧。分享给大家供大家参考。具体分析如下: 在mysql中我们结合php把一些文件导入到mysql中,这里就来分享一下我对15000条...

mysql5写入和读出乱码解决

我写的例子 复制代码 代码如下:<?  require("adodb/adodb.inc.php");  $conn=newadoconnection('mys...