标题中提到的错误的文档说
如果您的命令不同步;您现在无法在客户端代码中运行此命令,您正在以错误的顺序调用客户端函数。
例如,如果您正在使用 mysql_use_result() 并在调用 mysql_free_result() 之前尝试执行新查询,则可能会发生这种情况。如果您尝试执行两个返回数据的查询而不在两者之间调用 mysql_use_result() 或 mysql_store_result() ,也会发生这种情况。
从这里:http ://dev.mysql.com/doc/refman/5.0/en/commands-out-of-sync.html
但是在第一个查询中,我没有从 mysql 数据库中获取任何数据,我只是在插入。在第二个查询中,我从数据库中获取数据。
这是我的代码
$connection = mysqli_connect("localhost","username","password","tbl_msgs");
if(mysqli_connect_errno($connection))
{
die("Failed to connect to MySQL: " . mysqli_connect_error());
}
$query = "INSERT INTO users (total_comments, total_views)
VALUES ({$total_comments}, {$total_views});";
$query .= "INSERT INTO msgs (notifications) VALUES ({$notifications})";
mysqli_multi_query($connection,$query);
到这一步为止,一切都很好。但是当我执行以下查询时,它给出了错误
$select_query = "SELECT * FROM msgs WHERE msg_id = {$msg_id}";
$result_set = mysqli_query($connection,$select_query);
if(!$result_set) {
die(mysqli_error($connection));
}
在这里它给出了 Error Commands out of sync; you can't run this command now
。我无法理解这种情况
注意:查询中有任何问题,我已经直接对 PHPMyAdmin 执行了相同的查询,它工作正常。