我正在尝试在下面的代码中使用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个单独的查询也更好?
答案 0 :(得分:0)
更新为
// 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
的更多信息