【问题标题】:Stored procedure is not working with PHP call [duplicate]存储过程不适用于 PHP 调用 [重复]
【发布时间】:2012-05-27 14:15:25
【问题描述】:

可能重复:
Can't return a result set in the given context

我正在尝试使用 PHP 调用一个基本的存储过程。但是 mysql 会产生类似“PROCEDURE softland.getAllProducts can't return a result set in the given context”这样的错误。

存储过程

 DELIMITER //
 CREATE PROCEDURE GetAllProducts()
 BEGIN
 SELECT *  FROM products;
 END //
 DELIMITER ;

PHP代码是

<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("softland",$con);
$id = 1;
$result = mysql_query("call getAllProducts()");
echo $result;

if ($result === FALSE) {
die(mysql_error());
}
while($row=mysql_fetch_array($result)){
    echo "<br>".$row['name'];
}
echo "Succees";
 ?>

【问题讨论】:

  • 请检查问题更新。错误是“PROCEDURE softland.getAllProducts 无法返回给定上下文中的结果集”

标签: php mysql stored-procedures


【解决方案1】:

嗯,这个答案直接来自mysql_connect上的php页面:

$this->con = mysql_connect($this->h,$this->u,$this->p,false,65536);

告诉你的 mysql 客户端使用多语句支持(另见 mysql 客户端常量:http://php.net/manual/en/mysql.constants.php#mysql.client-flags

【讨论】:

  • 感谢您的宝贵时间。所以请说清楚我该如何解决这个问题?
  • 我已经用 $con=mysql_connect("localhost","root","",false,65536) 更新了代码。但仍然显示相同的错误消息
【解决方案2】:

试试这个,

Function GetProducts($out)
{
    $query.= "CREATE PROCEDURE GetAllProducts() ";
    $query.= "BEGIN";
    $query.= "SELECT *  FROM products;";
    $query.= "END";
    return $query;
}

在代码中放这个,

$result = mysql_query(GetProducts());

希望有效!!

【讨论】:

  • GetProducts($out)函数中的$out是什么?
  • 我在这里发布了几个问题,但没有得到答案。我真的很郁闷:(
【解决方案3】:

我认为问题在于您使用的是旧的 mysql 函数而不是 newer mysqli library

尝试按照this manual page 上的示例进行操作。

【讨论】:

    猜你喜欢
    • 2011-09-21
    • 2013-03-21
    • 2011-01-23
    • 2015-11-11
    • 1970-01-01
    • 2021-09-04
    • 2011-09-16
    • 1970-01-01
    • 2018-05-21
    相关资源
    最近更新 更多