加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 13:25:35 所属栏目:PHP教程 来源:网络整理
导读:我已将我的注册脚本从 mysql转换为 mysqli.我工作得很好,但它现在给了我错误 Commands out of sync; you can't run this command now 这是我用来注册用户的功能 function register_user($register_data) { global $myConnection;array_walk($register_data,'
我已将我的注册脚本从 mysql转换为 mysqli.我工作得很好,但它现在给了我错误
Commands out of sync; you can't run this command now

这是我用来注册用户的功能

function register_user($register_data) { 
global $myConnection;
array_walk($register_data,'array_sanitize'); 
//Make the array readable and seperate the fields from data 
$fields = '`' . implode('`,`',array_keys($register_data)) . '`'; 
$data = ''' . implode('','',$register_data) . '''; 
//Insert the data and email an activation email to the user 
mysqli_query($myConnection,"INSERT INTO `members` ($fields) VALUES ($data)") or die(mysqli_error($myConnection)); 
email($register_data['mem_email'],'Activate your account',"Hello " . $register_data['mem_first_name'] . ",nnThank you for creating an account with H Fencing. Please use the link below to activate your account so we can confirm you identity:nnhttp://blah.blah.co.uk/activate.php?mem_email=" . $register_data['mem_email'] . "&email_code=" . $register_data['email_code'] . "nn - David & Jay "); 
}

电子邮件使用我的阵列中的正确数据发送正常.但是没有数据插入数据库,我得到上面提到的错误.我之前从未遇到过这个错误.

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

更新

如果为查询创建变量并将变量直接粘贴到MySQL Workbench之类,则可以在执行之前检查语法.

<?php
            function myConnection(){
              $myConnection = mysqli_connect('localhost','my_user','my_password','my_db');
              return $myConnection;
            }   


    function register_user($register_data) { 
        array_walk($register_data,'array_sanitize'); 
        //Make the array readable and seperate the fields from data 
        $fields = '`' . implode('`,array_keys($register_data)) . '`'; 
        $data = "'" . implode("','",$register_data) . "'"; 
        //Insert the data and email an activation email to the user 
        $query = "INSERT INTO `members` ($fields) VALUES ($data)";
                    $myNewConnection = myConnection();          

                    if($result = mysqli_query($myNewConnection,$query)){ 
        email($register_data['mem_email'],nnThank you for creating an account with H Fencing. Please use the link below to activate your account so we can confirm you identity:nnhttp://blah.blah.co.uk/activate.php?mem_email=" . $register_data['mem_email'] . "&email_code=" . $register_data['email_code'] . "nn - David & Jay "); 
        mysqli_free_result($result);
         return ("Success");
        } else {
            echo $query;
            die(mysqli_error($myNewConnection));
        } 

    }

?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读