PHP(Version7.1)で以下のコードを実施したとき
<?php function addPictOverViewTable(PDO $db, String $picture_id, $title, $category){ try { $sql = "INSERT INTO picts_overview (picture_id, title, category, pins_count, register_datetime, update_datetime) VALUES (:picture_id, :title, :category, :pins_count, :register_datetime, :update_datetime)"; $stmt = $db -> prepare($sql); $stmt -> bindParam(':picture_id', $picture_id, PDO::PARAM_STR); $stmt -> bindParam(':title', $title, PDO::PARAM_STR); $stmt -> bindParam(':category', $category, PDO::PARAM_STR); $stmt -> bindValue(':pins_count', 0, PDO::PARAM_INT); $datetime = new DateTime(); $stmt -> bindValue(':register_datetime', $datetime->format('Y-m-d H:i:s'), PDO::PARAM_STR); $stmt -> bindValue(':update_datetime', $datetime->format('Y-m-d H:i:s'), PDO::PARAM_STR); } catch(PDOException $e) { echo $e->getMessage();//Remove or change message in production code } }
以下のエラーが発生します。
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 ')' at line 7
どうやらINSERT文が間違っているエラーのようですが、一向に原因が分からず、困り果てております。
予約語の可能性や、スキーマとの不一致なども確認してみましたが、正しそうでした。
少しでも何かヒントになる情報を頂ければ、大変有り難く思います。
宜しくお願い致します。
回答6件
あなたの回答
tips
プレビュー