7

这个简单的代码调用了两个 MySQL 过程,但是在第一个返回值之后,它在第二个查询中返回一个错误。

注意:单独运行第一个或第二个将正确返回每个。所以查询工作,只是不在一起。

完整的错误是: Invalid query: Commands out of sync; you can't run this command now

请有任何想法。

<?php

require_once ('connection.php');
//First Query and Output

$result = mysql_query("CALL C01_Client_Summary_ByAccount(1, '2012-02-27', '2013-03-29');");
if (!$result) { 
die('Invalid query: ' . mysql_error());
}
while($row=mysql_fetch_array($result))
{
echo $row['CommisionPercentage'];
}

mysql_free_result($result); 
//END First Query and Output

//Second Query and Output
$new2 = mysql_query("CALL C01_Client_Summary_ByBetType(1, '2012-02-27', '2013-03-29');");
if (!$new2) { 
die('Invalid query: ' . mysql_error());
}
while($row=mysql_fetch_array($new2))
{
echo $row['Turnover'];
}
//END Second Query and Output

?>
4

1 回答 1

5

PHP 的旧 MySQL 扩展无法与存储过程一起正常工作。不幸的是,似乎没有办法用它执行多个存储过程。问题是第一个过程留下了一些缓冲的结果集,导致第二个过程失败。但是,您可以使用 mysqli 扩展。这是有关如何执行此操作的一个很好的示例:

http://www.daniweb.com/web-development/php/threads/234868/error-commands-out-of-sync-you-cant-run-this-command-now

于 2013-03-12T23:15:13.247 回答