无法在给定的上下文中返回结果集

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

我有谷歌它,有人说这是MySQL的错误,有人说你应该改变你的mysqli驱动程序和….

情况:

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

我该怎么办!?

不知道这是你的问题的解决scheme,但如何使用更新版本的PHP?
PHP 5.2.4的确是相当老了 – 所以,如果这是PHP的mysqli驱动程序的错误,它可能已经被纠正,因为…

其实,在快速search之后,似乎就像你目睹的问题已经在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来testing吗?
我知道这些不是由Ubuntu提供的,即使在最后的Ubuntu稳定版本中:-(你可能需要从源代码编译:-(


还有一个想法是尝试mith PDO_MySql适配器:也许它会适用于那个?
有可能改变适配器而不会造成太多的麻烦/不需要花费数小时来testing?


正如你正在使用Zend Framework 1.9一样,下面是另一个你可能会感兴趣的post,可能更容易testing: 升级到1.8后的存储过程错误

试试这个简单的解决scheme是回到Zend Framework 1.7; 会不会有可能只是为了testing?

无论如何…祝你好运!
而且,如果您find解决scheme,不要忘记指出问题所在,以及如何解决问题;-)

答案是升级你的PHP,我刚刚升级到5.3.0,它的作品喜欢糖果!

我最近在合同上遇到了这个问题。 客户端使用windoze和PHP 5.2.6的代码库,我的安装是Linux和PHP 5.3.1无论我们做什么,他们不会合作,所以最终他们给了我一个windoze vista机器,我们安装了PHP 5.2 .6我们走了。 故事的道德:版本匹配计数。 奇怪的客户,我从来没有这样的任何其他工作之前。 但是,嘿,你什么都不知道。 绝对不是MySql的问题,只是PHP。

它也适用于PHP 5.2.10。

从早期的版本,我已经成功地使用mysqli :: multi_query调用有问题的过程,并得到正确的结果。

我知道这个问题很古老,但对于那些仍在使用5.2.4并且出现这个错误的人,你可能会考虑创build一个新的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 $_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. eg: "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); }