If you get Commands out of sync; you can’t run this command Now in
your client code,you are calling client functions in the wrong order.This can happen,for example,if you are using mysql_use_result() and
try to execute a new query before you have called MysqL_free_result().
It can also happen if you try to execute two queries that return data
without calling MysqL_use_result() or MysqL_store_result() in between.
从这里:http://dev.mysql.com/doc/refman/5.0/en/commands-out-of-sync.html
但是在First Query中我没有从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)); }
这里它使错误命令不同步;你现在不能运行这个命令.我无法理解这种情况
MysqLi_multi_query($connection,$query);
您需要先使用/存储结果,然后才能继续下一个查询:
由于您看起来并不真正关心第一个结果集,请在多个查询之后执行此操作.
do { $result = MysqLi_store_result($connection); MysqLi_free_result($result); }while(MysqLi_next_result());
MysqLi_close($connection); $connection = MysqLi_connect("localhost","tbl_msgs");
这一切都取决于您的要求.
原文地址:https://www.jb51.cc/php/132518.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。