使用PDO的UPDATE语法出错

时间:2013-04-02 08:18:26

标签: php mysql pdo sql-update

我正在尝试运行UPDATE而我收到语法错误。我正在使用php和PDO来创建UPDATE命令。我的语法出了什么问题?

  

更新教育WHERE userId =:userId AND fieldId =:fieldId SET   fieldId =:fieldId,educationTitle =:educationTitle,educationDegree   =:educationDegree,startDate =:startDate,endDate =:endDate,educationDescription =:educationDescription;

错误:

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   'WHERE userId ='35'AND fieldId ='4'SET fieldId ='4'附近,   educationTitle ='ththt'在第1行

更新:

我尝试在WHERE之后放置SET,如下面的示例所示,但我仍然遇到语法错误。

  

更新教育SET fieldId =:fieldId,educationTitle =   :educationTitle,educationDegree =:educationDegree,startDate =   :startDate,endDate =:endDate,educationDescription =   :educationDescription,WHERE userId =:userId AND fieldId =:fieldId;

1 个答案:

答案 0 :(得分:3)

WHERE放在SET之后。

UPDATE  education  
SET     fieldId = :fieldId, 
        educationTitle = :educationTitle, 
        educationDegree = :educationDegree, 
        startDate = :startDate, 
        endDate = :endDate, 
        educationDescription = :educationDescription
WHERE   userId = :userId AND 
        fieldId = :fieldId