神秘的错误1064

时间:2017-02-23 11:59:50

标签: mysql regex

我正在尝试将一个字符串插入MySQL数据库 - 它包含包含引号,星号,反斜杠等的正则表达式 - 以下是不工作的 - 任何想法如何纠正它?我也根据其他答案尝试了很多没有快乐的事情。

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()字符串。

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        Long NexClockTime = alarmManager.getNextAlarmClock().getTriggerTime();
        Long now = System.currentTimeMillis();
        Long timeLeft = NexClockTime - now;

另外,@ Del发现regexp是一个保留字,因此你不能将它用作表列名。您也可以尝试使用qa_db_query_sub('INSERT INTO `islamiqa_topics` (`title`, `description`, `regexp`) VALUES ($, $, $)', $title, $description, base64_encode($regexp)); (添加引号)