0
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
4

1 回答 1

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');";
于 2013-07-31T13:05:17.997 回答