我的代碼有問題嗎?如果其確定,那麼爲什麼我總是得到這個錯誤查詢中的Php/MYSql錯誤
PDOException:SQLSTATE [42000]:語法錯誤或訪問衝突: 您在您的SQL語法錯誤1064;在 C:**** \ class \ class.admin.php上,在'add ='Myaddress'WHERE id =''附近使用 線160
這裏是我的代碼:
function EditClient($uname,$email,$pname,$cname,$mob,$add,$cid)
{
$query = $this->dbh->prepare("
UPDATE client SET
uname = :username,
email = :email,
pname = :pname,
cname = :cname,
mob = :mob,
add = :addr
WHERE id = :id ");
$query->execute(array(
':username' => $uname,
':email' => $email,
':pname' => $pname,
':cname' => $cname,
':mob' => $mob,
':addr' => $add,
':id' => $cid
)); //here is the line 160
return $query->rowCount();
}
其中$ CID的值爲 「Myaddress」
'add'是mysql中的保留字 – Sadikhasan
@AshishBiswas如果答案有幫助,永遠不要忘記接受/ upvote – Sadikhasan
[由於在MySQL中使用保留字作爲表或列名稱導致的語法錯誤](http:// stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql) – vhu