2017-02-23 134 views
1

我想插入一个字符串到MySQL数据库 - 它包含正则表达式包含引号,星号,反斜杠等 - 以下不工作 - 任何想法如何纠正它?根据其他答案,我也尝试过没有快乐的特质。神秘的错误1064

qa_db_query_sub('INSERT INTO `^islamiqa_topics` (title, description, regexp) VALUES ($, $, $)', $title, $description, mysql_real_escape_string($regexp)); 

这是我的错误:

Database query error 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 'regexp) 
VALUES ('7/7', '3rd of March 1924 was the day the Ottoman' at line 1 

INSERT INTO `qa_islamiqa_topics` (title, description, regexp) VALUES ('7/7', '3rd of March 1924 was the day the Ottoman Caliphate was formally abolished in Turkey by Mustafa Kemal Atataurk.', '7/7(/2005)?|7(th)? july 2005|july 7.* 2005') 
+1

使用参数向数据库中插入值。 –

+0

您使用哪种客户端语言? –

回答

1

可以BASE64_ENCODE()添加到数据库之前的字符串。

qa_db_query_sub('INSERT INTO `islamiqa_topics` (`title`, `description`, `regexp`) VALUES ($, $, $)', $title, $description, base64_encode($regexp)); 

此外,@Del发现regexp是一个保留字,因此您不能将其用作表列名称。您也可以尝试使用regexp(加引号)

+0

我仍然得到相同的错误。 – Del

+0

我编辑了我的答案,请再试一次,表名前面有一个^字符 – Alex

+0

同样的问题...表名前面是qa_因此需要^ – Del