2016-12-05 116 views
0

我有查询是动态更新到一个迁移文件,当我执行确切的查询它会抛出这个错误,我已经尝试了很多,但没有任何工作! 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 'type':'text','filed_name':'Ture_st aare','order':'5','values':['Mr','Mrs','Miss']' at line 1这些查询有什么区别?

Query 1 
// working 
DB::statement("Insert Into custom_fields_configure (`table_name`, `configure`, `filed_name`, `module_id`,`created_at`,`updated_at`) values ('ads','test','cf_Ture_staare',22,now(),now());"); 

Query 2 
// Not working 
DB::statement("Insert Into custom_fields_configure (`table_name`, `configure`, `filed_name`, `module_id`,`created_at`,`updated_at`) values ('ads','{'type':'text','filed_name':'Ture_staare','order':'5','values':['Mr','Mrs','Miss'],'datalenght':'5'}','cf_Ture_staare',22,now(),now());"); 

这怎么解决?

+4

您似乎在一个字符串中使用了单引号作为一个值。只需加倍单引号,这样SQL就能正确解释它们。 –

+0

只需在“'”前添加“\”或用双引号替换单引号 – Beginner

+0

是的,它的作品对我来说,谢谢! @GordonLinoff,@ Newbee Dev –

回答

0

看来你试图插入这个值作为一个字符串。

{ '类型': '文本', 'filed_name': 'Ture_staare', '订单': '5', '值':[ '先生', '夫人', '小姐'] , “datalenght”:“5” }

这似乎有点过我,因为它看起来像极了文本里面去(如“类型”的:“文”,“datalenght”:“5” )不应该在那里。如果你需要把相同的值作为一个值,那么你需要添加“\”,以便可以将其作为单个字符串值。

希望这会有所帮助!