0
您好我在執行PDO準備語句時出錯。我的地方發展工作正常,但是當我嘗試插入在雲cleardb這個錯誤發生:PHP PDO執行錯誤,並插入cleardb
SQLSTATE [42000]:語法錯誤或訪問衝突:1142 INSERT命令剝奪了用戶'b2218f51d4a66e'@'191.235.136.58 '表 '用戶'' 在/var/www/php1/CRUD.php:52
function create_User($firstname, $lastname, $username, $password, $address, $city, $zip, $country, $email) {
global $dbh;
$this->password = $password;
$token = md5($this->salt1 . $this->password . $this->salt2);
$this->sth = $dbh->prepare('INSERT INTO `Php_Project`.`User`
(
userName,
passWord,
create_DateStamp,
e_mail)
VALUES
(
:username,
:token,
NOW(),
:email
);
「);
$this->sth->bindParam(':username', $username, PDO::PARAM_STR);
$this->sth->bindParam(':token', $token, PDO::PARAM_STR);
$this->sth->bindParam(':email', $email, PDO::PARAM_STR);
if ($this->sth->execute()) {
$this->message = "true";
} else {
$this->message = "false";
}
if ($this->message == "true") {
$userId = $dbh->lastInsertId();
$this->sth = $dbh->prepare('INSERT INTO `Php_Project`.`user_Detail`
(
firstName,
lastname,
adress,
zip,
city,
country,
userId)
VALUES
(
:firstname,
:lastname,
:address,
:zip,
:city,
:country,
:userId
);');
$this->sth->bindParam(':firstname', $firstname, PDO::PARAM_STR);
$this->sth->bindParam(':lastname', $lastname, PDO::PARAM_STR);
$this->sth->bindParam(':address', $address, PDO::PARAM_STR);
$this->sth->bindParam(':zip', $zip, PDO::PARAM_INT);
$this->sth->bindParam(':city', $city, PDO::PARAM_STR);
$this->sth->bindParam(':country', $country, PDO::PARAM_STR);
$this->sth->bindParam(':userId', $userId, PDO::PARAM_STR);
if ($this->sth->execute()) {
$this->message = true;
} else {
$this->message = false;
}
}
}
如果是這樣爲什麼這個查詢工作正常從MySQL工作臺:INSERT INTO'as_754979fd4dcbfcb'.'user' ('userId', 'userName', 'passWord', 'create_DateStamp', 'update_DateStamp', 'e_mail') VALUES (默認, 「1111」, 「2222」, 現在(), 默認, 「[email protected]」); – surajnew55
您是否以用戶'b2218f51d4a66e'的身份登錄Workbench?另外請注意,用戶標識符的第二部分也是計數的(例如,'b2218f51d4a66e'@191.235.136.58'與'b2218f51d4a66e'@'%'不同,後者允許從任何主機訪問而不是一個主機) – GMemory