gpt4 book ai didi

php - mysqli_multi_query 命令不同步错误 - 未插入数据库

转载 作者:行者123 更新时间:2023-11-30 23:11:00 25 4
gpt4 key购买 nike

我正在尝试在下面的代码中使用 mysqli_multi_query 函数,但遇到了这个错误:

命令不同步;你现在不能运行这个命令

// add call stats to incoming nodes
$sql = "INSERT INTO `" . node_name_formatter($i_route) . "` ";
$sql .= " (`timeperiod`, ";
$sql .= " `exchange_id`, ";
$sql .= " `calls_in`) ";
$sql .= "VALUES ('" . date('Y-m-d H:i:s', $time) . "', ";
$sql .= " '$exchange_id', ";
$sql .= " '1') ";
$sql .= "ON DUPLICATE KEY UPDATE ";
$sql .= " `calls_in` = `calls_in`+1;";

// add call stats to outgoing nodes
$sql .= "INSERT INTO `" . node_name_formatter($o_route) . "` ";
$sql .= " (`timeperiod`, ";
$sql .= " `exchange_id`, ";
$sql .= " `calls_out`) ";
$sql .= "VALUES ('" . date('Y-m-d H:i:s', $time) . "', ";
$sql .= " '$exchange_id', ";
$sql .= " '1') ";
$sql .= "ON DUPLICATE KEY UPDATE ";
$sql .= " `calls_out` = `calls_out`+1";

// echo $sql . '<br><br>';
mysqli_multi_query($connection, $sql) or die(mysqli_error($connection));

我正在按照 php manual 上的说明执行此查询.使用此函数还是以正常的 mysqli_query 方式执行 2 个单独的查询更好?

最佳答案

更新为

// add call stats to incoming nodes
$sql = "INSERT INTO `" . node_name_formatter($i_route) . "` ";
$sql .= " (`timeperiod`, ";
$sql .= " `exchange_id`, ";
$sql .= " `calls_in`) ";
$sql .= "VALUES ('" . date('Y-m-d H:i:s', $time) . "', ";
$sql .= " '$exchange_id', ";
$sql .= " '1') ";
$sql .= "ON DUPLICATE KEY UPDATE ";
$sql .= " `calls_in` = `calls_in`+1;";

// add call stats to outgoing nodes
$sql .= "INSERT INTO `" . node_name_formatter($o_route) . "` ";
$sql .= " (`timeperiod`, ";
$sql .= " `exchange_id`, ";
$sql .= " `calls_out`) ";
$sql .= "VALUES ('" . date('Y-m-d H:i:s', $time) . "', ";
$sql .= " '$exchange_id', ";
$sql .= " '1') ";
$sql .= "ON DUPLICATE KEY UPDATE ";
$sql .= " `calls_out` = `calls_out`+1;";

// echo $sql . '<br><br>';
mysqli_multi_query($connection, $sql) or die(mysqli_error($connection));

您必须使用 mysqli_next_result 遍历结果以获取每个查询的结果。

在此处查看有关错误 Commands out of sync 的更多信息

关于php - mysqli_multi_query 命令不同步错误 - 未插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19725038/

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