我有一個表:MySQL的 - 在重複鍵
Saves
-----
UserId (int primary key)
Save (blob)
SaveBackup (blob)
這是填充了這一點:
Saves(22, 'xyz', '')
我提交以下材料:
$stmt = $db->prepare("INSERT INTO Saves (UserId, Save, SaveBackup) "
. "VALUES (:UserId1, :Save1, '') ON DUPLICATE KEY "
. "UPDATE Saves SET SaveBackup=Save, Save=:Save2 "
. "WHERE UserId=:UserId2");
$stmt->execute(array(':Save1' => 'zzz',
':Save2' => 'zzz',
':UserId1' => 22,
':UserId2' => 22));
它不工作,您的SQL代碼中出現錯誤。它工作正常,沒有所有東西在ON DUPLICATE KEY之前(包括)。
您是否閱讀過文檔? http://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html –