在PHP中,用下面的代碼:php如何插入逗號分隔json格式的多個字符串作爲一個值到mysql表?
$j_id = $jData[$j]['itop_id'];
$res = '"name":"' . $jData[$j]['label'] . '","x":'. $jData[$j]['x'] . ',"y":' . $jData[$j]['y'] . ',"url":"' . $jData[$j]['icon_url'] . '"';
我能得到的值:
$j_id = 1;
$res = "name":"AOL network","x":1032.5,"y":180,"url":"http://localhost/pathfind/web/env-production/itop-config-mgmt/images/business-process.png"
當我嘗試插入的$ j_id價值觀和$資源到MySQL表用下面的代碼:
$sql = 'INSERT INTO coordinate_info (id,coordinate_res) VALUES ('.$j_id.','. $res.')';
我得到了錯誤:
Error: INSERT INTO coordinate_info (id,coordinate_res) VALUES (1,"name":"AOL network","x":1032.5,"y":180,"url":"http://localhost/pathfind/web/env-production/itop-config-mgmt/images/business-process.png") You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':"AOL network","x":1032.5,"y":180,"url":"http://localhost/pathfind/web/env-produ' at line 1
我想插入逗號分隔多個JSON格式的字符串到MySQL表中作爲一個列值。 你能給我一些建議嗎? 在php中,如何將逗號分隔的值作爲一個值保存到mysql表中?
預處理語句或逃避你的字符串將是不錯 – Naruto
將幫助:'$ SQL =「INSERT INTO coordinate_info(ID,coordinate_res) VALUES(「。$ j_id。」,'$ res')「;' – devpro