“mysqli-> multi_query”at在第二次查询时抛出sql语法错误

时间:2013-07-31 13:01:28

标签: php sql oop

public function multiQueryInsert($query){
    if($this->conn->multi_query($query)){
        do{
            $this->conn->store_result();
            /*if($result = $this->conn->store_result()){
                while($row = $result->fetch_row()){
                    return $row;
                }*/
                //$result->free();
            //}
            $this->conn->more_results();
        }
        while($this->conn->next_result());
        return true;
    }
    else{
        return $this->conn->errno;
    }
    $this->conn->close();
}

$query = "INSERT INTO `table_name`(`name`, `phone`, `address`, `email`, `cell`, `pcf`, `church`, `group`, `zone`, `dob`, `occupation`, `status`) VALUES ('$names','$phone','$address','$email','$cell','$pcf','$church','$group','$zone','$dob','$occupation','$status')";
$username = explode(' ',$names);
$fname = strtolower($username[0]);
$password = $data;
$query .= "INSERT INTO `table_name2` (`uid`, `pswd`, `Name`, `Email`) VALUES ('$fname','$password','$names','$email')";

if($db->multiQueryInsert($query) === TRUE){
    echo '<div class="success">Partner added successfully</div>';
}
else{
    die('Error adding partner: '.$db->conn->error);
}

第一个代码是执行multi_query的方法,而其他代码是传递给方法的查询。引发的错误是添加伙伴错误:

您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在附近使用正确的语法:

"INSERT INTO `cec_users` (`uid`, `pswd`, `Name`, `Email`) VALUES ('kjvhm,bhjkl','')" at line 1

1 个答案:

答案 0 :(得分:2)

尝试在第一次插入查询结束时使用semicolon,如下所示:

$query = "INSERT INTO `table_name`(`name`, `phone`, `address`, `email`, `cell`, `pcf`, `church`, `group`, `zone`, `dob`, `occupation`, `status`) VALUES ('$names','$phone','$address','$email','$cell','$pcf','$church','$group','$zone','$dob','$occupation','$status');";
相关问题