由于某种原因,我在第二行包含的代码中出现了这个错误:
致命错误:未捕获的异常' PDOException' with message' SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与您的MySQL服务器版本相对应的手册,以便在#div; div =' CA'附近使用正确的语法。在哪里vid =' 400373''在第1行'在/home/stretch045/public_html/scripts/auth.php:12堆栈跟踪:#0 /home/stretch045/public_html/scripts/auth.php(12):PDO->准备(' UPDATE用户SE。 ..')#1 /home/stretch045/public_html/index.php(35):Auth-> checkToken(' 94257b73ea4ed51 ...')#2 {main}引入/第12行的home / stretch045 / public_html / scripts / auth.php
码
$conn = $this->db;
$stmt = $conn->prepare("UPDATE users SET rating='".$xml->rating."', atc='".$xml->ratingatc."', pilot='".$xml->ratingpilot."', div='".$xml->division."' WHERE vid='".$xml->vid."'");
$stmt->execute();
if($stmt->rowCount()==0){
$stmt = $conn->prepare("INSERT INTO users (vid, fname, lname, rating, atc, pilot, div) VALUES (".$xml->vid.",".$xml->firstname.",".$xml->lastname.",".$xml->rating.",".$xml->ratingatc.",".$xml->ratingpilot.",".$xml->division.")");
$stmt->exec($stmt);
echo 'data inserted into db';
}
答案 0 :(得分:3)
div
是reserved keyword in MySQL,需要通过反引号进行转义。
INSERT INTO users (vid, ..., `div`) VALUES (...)