解析xml文件并将其添加到数据库时,脚本运行时显示错误:
$sql->exec("INSERT INTO 'example' VALUES('$id', '$title', '$link')");
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 ''example' VALUES('phpmysqljquery-przeciagnij-z-wy' at line 1
谁能说一下哪里出了问题吗?
最佳答案
您使用了错误的引用风格。数据库、表和列标识符使用不同的方法:
INSERT INTO `example` VALUES (?,?,?)
双引号和单引号仅用于字符串。您无法将内容插入字符串中。
关于php - 添加数据时的SQLSTATE [42000],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45826185/