这个问题已经有了答案:
Syntax error due to using a reserved word as a table or column name in MySQL
1个答案
我正在尝试从csv更新一个表。尝试插入行时出现以下错误。其他查询在同一个循环中进行,但它在特定的循环中停止。
我已经检查了所有的值是否与db表完全匹配。
我对可能的问题没有主意。有什么建议吗?
询问

INSERT INTO user_interests (member_num,ABU,ADD,ADOP,ANO,ANX,BER,BULL,COMP,CONF,CONT,CUL,DEP,DIS,DOM) VALUES (:member_num,:ABU,:ADD,:ADOP,:ANO,:ANX,:BER,:BULL,:COMP,:CONF,:CONT,:CUL,:DEP,:DIS,:DOM)

错误
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ADD,ADOP,ANO,ANX,BER,BULL,COMP,CONF,CONT,CUL,DEP,DIS,DOM) VALUES ('5323',1,1,1,1' at line 1' in /Applications/XAMPP/xamppfiles/htdocs/ukcp/phpLibraries/users/userPopulateInts.php:45 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/ukcp/phpLibraries/users/userPopulateInts.php(45): PDOStatement->execute() #1 /Applications/XAMPP/xamppfiles/htdocs/ukcp/userprofile.php(14): userPopulateInts->ints1() #2 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/ukcp/phpLibraries/users/userPopulateInts.php on line 45

守则
  if ( !empty($int) && !empty($intColon) ) {
                    $sql = 'INSERT INTO user_interests (member_num,'. implode(",", $int) .') VALUES (:member_num,'. implode(",", $intColon) .')';
                    $dbQuery = $this->db()->prepare($sql);
                    echo $sql ."<br>";
                    $dbQuery->bindValue(":member_num", $data[0], PDO::PARAM_INT);
                    foreach ($intColon as $val) {
                        $dbQuery->bindValue($val, 1, PDO::PARAM_INT);
                    }

                    $dbQuery->execute();
                }

最佳答案

你需要像用反勾号退出ADD一样退出reserved words

INSERT INTO user_interests (member_num, ABU, `ADD`, ...

关于php - 带有消息'SQLSTATE [42000 的未捕获异常'PDOException',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19833881/

10-09 00:34