mysql插入json数据
在试图将json数据存入mysql时,出现了错误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数据没有用引号的问题,并且必须是单引号原代码inse...
·
在试图将json数据存入mysql时,出现了错误
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数据没有用引号的问题,并且必须是单引号
原代码
insert into `food_info` (`food`,`difficult`)
VALUES ([\"鸡胸肉:500克\", \"奥尔良腌肉料:30克\"] , 普通 )
修改后
insert into `food_info` (`food`,`difficult`)
VALUES ('[\"鸡胸肉:500克\", \"奥尔良腌肉料:30克\"]' , '普通')
如果是通过变量插入数据
insert into `food_info` (`food`,`difficult`) VALUES ('%s') % value_str
"insert into hello ('food_info') (`food`,`difficult`) VALUES ('{value}')".format(value=value)
参考文章https://www.jb51.net/article/149024.htm
更多推荐
已为社区贡献1条内容
所有评论(0)