前提・実現したいこと
MySQLのJSON型のカラムを用いて,以下のようなJSON形式のデータを格納したいです.
{"nodes":[{"id":0,"title":"new concept0","x":537.5,"y":200},
{"id":1,"title":"new concept1","x":537.5,"y":400}]}
テーブルは次の通りです.
CREATE TABLE json_test
(col
, JSON);
該当のソースコード
php
1 $stmt = $pdo->prepare("INSERT INTO 'json_test' VALUES (?)"); 2 3 $stmt->execute(array($json_data)); 4 5 echo $json_data;
mysql
1 INSERT INTO `json_test` VALUE 2('{"nodes":[{"id":0,"title":"new concept0","x":537.5,"y":200}, 3{"id":1,"title":"new concept1","x":537.5,"y":400}]}');
$json_dataには格納したいJSON形式のデータが格納されており,実際の出力結果も問題ありません.
しかし,
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 ''json_test' VALUES ('{"nodes":[{"id":0,"title":"new concept0","x"
とエラーが表示され,DBに格納できません.
原因がわかる方はいませんか.
回答1件
あなたの回答
tips
プレビュー