我想将查询插入到数据库中,该数据库中包含单引号。我怎么能在PHP中处理这个?
我的查询是:
ERROR 1064 (42000): 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 'A'', 'in queue', ' (Scheduled Query #413) Pull all items where National Status C' at line 1
它显示错误
{{1}}
答案 0 :(得分:1)
将单引号(')的值替换为 BackSlash&单引号(\')或两个单引号('')
试试这个:
opacity = 0.1
或强>
INSERT INTO QUERY (date_time, userid, user_traits, query_sql, STATUS, description, is_scheduled_row)
VALUES ('2016-01-06 02:39:01', '307', '0,3598,1937,13891,37746,22082,2596,2431,12850,3917,1234784,44712,14638,14418,12850,2631,25003,11428,27450,2592,23593,11441,2826,36330,32219,32351,20720,13997,2594,2467,15687', 'Select * from gl_base_schema.item where national_status_cd = ''A''', 'in queue', ' (Scheduled Query #413) Pull all items where National Status Code is ''A''', 1);
答案 1 :(得分:0)
$query = "Select * from gl_base_schema.item where national_status_cd = 'A'";
$sql = "insert into query (date_time, userid, user_traits, query_sql, status, description, is_scheduled_row) values ('2016-01-06 02:39:01', '307', '0,3598,1937,13891,37746,22082,2596,2431,12850,3917,1234784,44712,14638,14418,12850,2631,25003,11428,27450,2592,23593,11441,2826,36330,32219,32351,20720,13997,2594,2467,15687', '."'".$query."'".', 'in queue', ' (Scheduled Query #413) Pull all items where National Status Code is \'A\'', 1)";
答案 2 :(得分:0)
你可以使用 double 和单引号组合:
'A'
您可以将"'A' test"
此字符串用于另一个字符串,而不能将其用作grid.addView(newMonster);
答案 3 :(得分:-1)
如果您有'A''
,请将其设为'A'''
。额外的'
会转义下一个'
,因此您需要''
一个'
。希望有所帮助。