我试图将结果集放入数组中..因此我做了以下尝试,结果证明是成功的
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$$
任何人都可以发现为什么它在普通查询中工作正常,并且它返回存储过程的错误。.我一直在尝试解决此问题一段时间,但没有任何效果
任何人都可以帮助我解决这个问题以将其与存储过程一起使用吗
存储过程不适用于 Mysql_* 函数。
贝特切换到PDO。