我有以下查询可以正常工作:
SET @var := 'test';
INSERT INTO yi5vu_roksprocket_items (module_id, provider, params)
VALUES ('122', 'simple', @var)
但如果我改变下面写的变量就不再有用了。
SET @var := '{"_article_title":"Simple Item 1","strips_item_title":"-none-","strips_item_image":"{'type':'mediamanager','path':'http:\/\/i.imgur.com\/fenrJmj.png','preview':'','link':'index.php?option=com_media&view=images&layout=default&tmpl=component&e_name=items_simple_1__params_strips_item_image'}","strips_item_link":"-default-","strips_item_description":"<html><body><div id=\"d_clip_button1\" class=\"btn btn-primary\" data-clipboard-text=\"[img]http:\/\/i.imgur.com\/fenrJmj.png[\/img]\" title=\"Copy.\"\">Copy<\/div> <script type=\"text\/javascript\" src=\"ZeroClipboard.js\"><\/script><script type=\"text\/javascript\"> var client = new ZeroClipboard( document.getElementById('d_clip_button1') );<\/script><\/body><\/html>","tabs_item_title":"-default-","tables_item_title":"-default-","lists_item_title":"-default-","mosaic_item_title":"-default-","grids_item_title":"-default-","quotes_item_description":"-default-","grids_item_description":"-default-","tables_item_description":"-default-","tabs_item_icon":"-default-","mosaic_item_description":"-default-","tabs_item_link":"-default-","lists_item_image":"-default-","quotes_item_image":"-default-","tables_item_image":"-default-","grids_item_image":"-default-","mosaic_item_image":"-default-","mosaic_item_link":"-default-","tabs_item_description":"-default-","grids_item_link":"-default-","tables_item_price":"-none-","tables_item_feature_1":"-none-","quotes_item_author":"-none-","lists_item_link":"-default-","mosaic_item_tags":"-article-","sliders_item_title":"-default-","features_item_title":"-default-","quotes_item_subtext":"-none-","tables_item_feature_2":"-none-","sliders_item_description":"-default-","headlines_item_image":"-default-","tables_item_feature_3":"-none-","lists_item_description":"-default-","quotes_item_link":"-default-","features_item_description":"-default-","quotes_item_direction":"-bottomleft-","features_item_image":"-default-","sliders_item_image":"-default-","headlines_item_link":"-default-","tables_item_feature_4":"-none-","tables_item_link":"-default-","features_item_link":"-default-","headlines_item_description":"-default-","sliders_item_link":"-default-","tables_item_link_text":"Buy Now"}';
INSERT INTO yi5vu_roksprocket_items (module_id, provider, params)
VALUES ('122', 'simple', @var)
导致此问题的原因是什么?我认为它是单引号或背引号,但我已尝试过每种组合。得到1064查询错误。
我只是想把@var中的内容拿出来并注入params。
答案 0 :(得分:3)
由于你的字符串以单引号开头,你不能在字符串本身中包含任何其他单引号,除非它们前面有反斜杠。
所以不要这样做&#39;这是一个不好的字符串,不要做这个&#39;很好。