MySQL语法错误-试图在不删除/创建新主键的情况下更新行


MySQL Syntax Error - Trying to update row without deleting/creating a new primary key

在PHP脚本失败后,我在SQL中尝试了这个和它的多个变体,它告诉我语法错误。

INSERT INTO qarows (questions, answers) VALUES(test, test) WHERE id='735'

这是我的数据库结构:https://i.stack.imgur.com/ot8cH.jpg


这是我开始使用的PHP脚本:

function updateDatabase($compare){
    $update = $this->dbh->prepare("
            INSERT INTO qarows (
            questions, answers, updateTimeUnicode, updateTimeNatural
            ) VALUES (
            :questions, :answers, :updateTimeUnicode, :updateTimeNatural
            ) WHERE id=:id
            ");
    $update->execute(array(
        ':questions' => $this->question, 
        ':answers' => $this->answer,
        ':updateTimeUnicode' => $this->updateTimeUnicode,
        ':updateTimeNatural' => $this->updateTimeNatural,
        ':id' => $this->id
        ));

谢谢你的帮助。

语法需要像这个

update qarows set questions="something",answers="someother",updateTimeUnicode="whatever",其中id=735;

你不能在主键(id列)已经存在的地方插入一行,我相信你想做的是更新它:

UPDATE qarows SET questions = 'test', answers 'test' WHERE id='735'