我试图将结果集放入数组中..因此我做了以下尝试,结果证明是成功的
while($row = mysql_fetch_array($table_count)){
$table = $row["TABLE_NAME"];
foreach ($tables as $table) {
$excute = mysql_query("
SELECT DISTINCT b.ID, name, accountname, c.accountID, status, total_impr, min(a.timestamp), max(a.timestamp)
FROM ",table_1," a INNER JOIN bookers b on a.ID = b.ID INNER JOIN accounts c on b.accountID = c.accountID
WHERE a.timestamp > DATE_ADD(NOW(), INTERVAL -1 YEAR)
GROUP BY ID;") or die(mysql_error());
$result = mysql_fetch_assoc($excute);
var_dump($result);
}
然后,为了提高代码的质量,我在查询中包含了该查询...之后,当我调用存储过程如下所示时,会出现错误说
Commands out of sync; you can't run this command now
代码
while($row = mysql_fetch_array($table_count)){
$table = $row["TABLE_NAME"];
foreach ($tables as $table) {
$excute = mysql_query("CALL mySP_1('$table')") or die(mysql_error());
$result = mysql_fetch_assoc($excute);
var_dump($result);
}
存储的进程
BEGIN
SET @sqlstring = CONCAT("
SELECT DISTINCT b.ID, name, accountname, c.accountID, status, total_impr, min(a.timestamp), max(a.timestamp)
FROM ",table_1," a INNER JOIN bookers b on a.ID = b.ID INNER JOIN accounts c on b.accountID = c.accountID
WHERE a.timestamp > DATE_ADD(NOW(), INTERVAL -1 YEAR)
GROUP BY ID;");
PREPARE stmt FROM @sqlstring;
EXECUTE stmt;
END$$
任何人都可以发现为什么它在正常查询下工作正常并且它会在存储的情况下返回错误..我一直在尝试修复此问题但是没有任何效果
任何人都可以帮我解决这个问题,使用存储过程