当我尝试在发送回结果集的mysql中调用存储过程时,它一直告诉我“不能在给定的上下文中返回结果集”。

我已经谷歌了,有些人说这是mysql的bug,有些人说你应该改变你的mysqli驱动程序......

情况:

使用mysqli驱动程序客户端API库版本5.0.51a,PHP版本5.2.4-2ubuntu5.6,使用Zend 1.9 RC 1 Mysqli适配器。

我该怎么做!?

有帮助吗?

解决方案

不确定这是否是您问题的解决方案,但是如果尝试使用更新版本的PHP呢?
PHP 5.2.4肯定很老 - 所以,如果它是PHP的mysqli驱动程序中的一个错误,它可能已经被纠正了...

实际上,在快速搜索之后,似乎在PHP 5.2.3和PHP 5.2.4之间引入了一个类似于您正在目击的问题(并且仍然在PHP 5.2.5中)。
请参阅错误#42548:PROCEDURE xxx无法返回给定的结果集上下文(适用于5.2.3 !!)

您是否可以使用PHP 5.2.9或5.2.10进行测试?
我知道这些不是由Ubuntu提供的,即使在最后一个Ubuntu稳定版本中:-(你可能需要从源代码编译: - (


另一个想法是尝试使用PDO_MySql适配器:也许它适用于那个?
有可能更换适配器而不会造成太多麻烦/无需花费数小时进行测试?


当您使用Zend Framework 1.9时,这是您可能感兴趣的另一篇文章,可能更容易测试:升级到1.8后存储过程错误

尝试的简单解决方案是返回Zend Framework 1.7;你有可能只是为了测试吗?

,点击 无论如何......祝你好运!
而且,如果你找到解决方案,不要忘记指明问题是什么,以及你是如何解决的; - )

其他提示

答案是升级你的php,我刚刚升级到5.3.0,它的作品就像Candy!

我最近在合同上遇到了这个问题。客户端在windoze和php 5.2.6上使用了代码库,我的安装是linux和php 5.3.1无论我们做了什么,他们都不会合作,所以最后他们给了我一台windoze vista机器,我们安装了php 5.2 .6然后我们去了。故事的道德:版本匹配计数。奇怪的cus我从来没有在任何其他工作中遇到过这种情况。但是,嘿,你不可能知道一切。绝对不是MySql问题,只是PHP。

它也适用于PHP 5.2.10。

从早期版本开始,我已成功使用mysqli :: multi_query来调用有问题的程序并获得正确的结果。

我知道这个问题很古老,但对于那些仍在使用5.2.4并且遇到此错误的人,你可以考虑创建一个新的mysql PDO对象来解决这个问题。

我仍然在我的开发服务器上使用5.2.4来确保我开发的WordPress插件的向后兼容性。

下面是程序调用的包装,我用它来成功调用5.2.4(在我的开发服务器上运行)中的程序,这通常会给我带来错误,以及我的生产服务器(运行更新的版本)不给出错误。

它的WordPress具体,但使用直接php修改它并不困难。

/*
* Need to cache connection so we don't keep creating connections till we hit max.
*/

private 

我知道这个问题很古老,但对于那些仍在使用5.2.4并且遇到此错误的人,你可以考虑创建一个新的mysql PDO对象来解决这个问题。

我仍然在我的开发服务器上使用5.2.4来确保我开发的WordPress插件的向后兼容性。

下面是程序调用的包装,我用它来成功调用5.2.4(在我的开发服务器上运行)中的程序,这通常会给我带来错误,以及我的生产服务器(运行更新的版本)不给出错误。

它的WordPress具体,但使用直接php修改它并不困难。

<*>dbhCache=null; /** * mySQL Call Proc * * Provides a wrapper around calling a mySQL stored procedure to ensure against a 5.2.4 bug that * causes procedure calls to fail. * Error:'can't return a result set in the given context' * * references: * http://stackoverflow.com/questions/1200193/cant-return-a-result-set-in-the-given-context * http://php.net/pdo_mysql#69592 //i got empty result set but pointed me in the right direction * http://php.net/pdo_mysql#80306 //this worked, but returned 0-indexed and assoc, i edited it so it only returns assoc mimicking $wpdb->get_results( * http://www.php.net/manual/en/pdo.connections.php * http://www.php.net/manual/en/pdostatement.fetch.php explains about FETCH_ASSOC * * @param string $proc The mySQL stored procedure string, including paramaters, but without the call statement. e.g.: "my_procedure_name('my_paramater')"; * @return string The results of the procedure call */ public function mySQLCallProc( $proc ) { global $wpdb; $query = "call $proc"; try { /* * Attempt to call the procedure normally. * */ $query_result = $wpdb->get_results( $query, ARRAY_A ); /* * Check for a database error * and throw an exception if one is found. * We can then attempt it again using a workaround. */ if ( $wpdb->last_error !== '' ) { throw new Exception( 'Database Error While Calling Procedure' ); } } catch ( Exception $e ) { try { /* * Create a PDO Object for the connection */ if ( is_null($this->_dbhCache)) { $dbh = new PDO( 'mysql:host=' . DB_HOST . ';port=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD, array( PDO::ATTR_PERSISTENT => true ) ); $this->_dbhCache=$dbh ; }else{ $dbh = $this->_dbhCache; } /* * Prepare and call the procedure. */ $stmt = $dbh->prepare( "call $proc" ); $stmt->execute(); /* * fetch all rows into an associative array. */ $query_result = $stmt->fetchAll( PDO::FETCH_ASSOC ); //FETCH_ASSOC gets results as an assoc array. without it, you'll receive both assoc and 0-indexed array } catch ( PDOException $e ) { print "Error!: " . $e->getMessage() . "<br/>"; die(); } } return ($query_result); }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top