参见英文答案 >
Syntax error due to using a reserved word as a table or column name in MySQL 1个
我正在尝试从CSV更新表.尝试插入行时出现以下错误.其他查询在同一个循环中进行,但它在特定的循环中停止.
我已经检查了所有的值是否与数据库表完全匹配,他们确实如此.
我对可能出现的问题缺乏想法.有什么建议?
查询
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 ."
";
$dbQuery->bindValue(":member_num", $data[0], PDO::PARAM_INT);
foreach ($intColon as $val) {
$dbQuery->bindValue($val, 1, PDO::PARAM_INT);
}
$dbQuery->execute();
}