我正在简单地进行多个INSERT INTO的工作,在phpmyadmin中可以正常工作。
当我在php中执行相同的代码时,出现错误:
1064您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册,以在'INSERT INTO fm_support_cont
(sup_id_cont
,mail
,phone
)值附近使用正确的语法((SELECT s在第二行
谢谢:-)
INSERT INTO `fm_support` (`name`, `surname`, `role_id_sup`) VALUES (?,?,?);
INSERT INTO `fm_support_cont` (`sup_id_cont`, `mail`, `phone`) VALUES ((SELECT sup_id FROM `fm_support` WHERE name = ? AND surname = ?),?,?);
INSERT INTO `fm_user` (`user`, `isadmin`, `user_data`) VALUES (?,?,(SELECT sup_id FROM `fm_support` WHERE name =? AND surname = ?));
我使用的PHP代码:
private function includeNewUser()
{
$data = $this->d;
$newName = $data[0];
$newSurname = $data[1];
$newRole = $data[2];
$newEmail = $data[3];
$newPhone = $data[4];
$newUser = $data[5];
$newIsadmin = $data[6];
$newApw = password_hash($data[7], PASSWORD_DEFAULT);
$SQL = " INSERT INTO `fm_support` (`name`, `surname`, `role_id_sup`) VALUES (?,?,?);
INSERT INTO `fm_support_cont` (`sup_id_cont`, `mail`, `phone`) VALUES ((SELECT sup_id FROM `fm_support` WHERE name = ? AND surname = ?),?,?);
INSERT INTO `fm_user` (`user`, `isadmin`, `user_data`) VALUES (?,?,(SELECT sup_id FROM `fm_support` WHERE name =? AND surname = ?));";
$conn = $this->connect();
if($stmt = $conn->prepare($SQL)) {
$stmt->bind_param("ssisssssiss", $newName, $newSurname, $newRole, $newName, $newSurname, $newEmail, $newPhone, $newUser, $newIsadmin, $newName, $newSurname);
$stmt->execute();
//$result = $stmt->get_result();
//$insertResult = $result->fetch_assoc();
if($newIsadmin == 1)
{
$stmt = $db->prepare("INSERT INTO `fm_apw`(`pw_for`, `pw`) VALUES ((SELECT id FROM fm_user WHERE user = ?), ?);");
$stmt->bind_param("ss",$newUser, $newApw);
$stmt->execute();
}
$result = true;
}
else
{
$result = $conn->errno . ' ' . $conn->error;
echo $result; // 1054 Unknown column 'foo' in 'field list'
//$result = false;
}
return $result;
}
}