gpt4 book ai didi

php - 尝试获取存储过程结果时出错,但普通查询工作正常

转载 作者:行者123 更新时间:2023-11-29 23:13:15 24 4
gpt4 key购买 nike

我试图将结果集放入数组中。因此我做了以下尝试,结果是成功的

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 .

关于php - 尝试获取存储过程结果时出错,但普通查询工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27979403/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com