我尝试插入参数时插入数据库查询失败了吗?

时间:2015-04-21 07:09:24

标签: mysql

我有桌子:

qa_eventlog (datetime, ipaddress, userid, handle, cookieid, event, params)

当我尝试运行此查询时:

INSERT INTO qa_eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) VALUES (NOW(), '10.88.11.123', '52', 'johnanhquan', NULL, 'q_edit', 'postid=913\ttitle=S\xe1\xbb\xb1 kh\xc3\xa1c nhau gi\xe1\xbb\xafa ROUTINES (Trans...\tcontent=Xin cho em h\xe1\xbb\x8fi s\xe1\xbb\xb1 kh\xc3\xa1c bi\xe1\xbb\x87t gi\xe1...\tformat=\ttext=Xin cho em h\xe1\xbb\x8fi s\xe1\xbb\xb1 kh\xc3\xa1c bi\xe1\xbb\x87t gi\xe1...\ttags=asql,bsql\textra=\tname=\toldquestion=array(72)\tsilent=1\toldtitle=S\xe1\xbb\xb1 kh\xc3\xa1c nhau gi\xe1\xbb\xafa ROUTINES (Trans...\toldcontent=Xin cho em h\xe1\xbb\x8fi s\xe1\xbb\xb1 kh\xc3\xa1c bi\xe1\xbb\x87t gi\xe1...\toldformat=\toldtags=asql,bsql\ttitlechanged=\tcontentchanged=\ttagschanged=')

我收到错误:

PHP Question2Answer MySQL query error 1366: Incorrect string value: '\\xE1...\\x09f...' for column 'params' at row 1 - Query: INSERT INTO qa_eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) VALUES (NOW(), '10.88.11.123', '52', 'johnanhquan', NULL, 'q_edit', 'postid=913\ttitle=S\xe1\xbb\xb1 kh\xc3\xa1c nhau gi\xe1\xbb\xafa ROUTINES (Trans...\tcontent=Xin cho em h\xe1\xbb\x8fi s\xe1\xbb\xb1 kh\xc3\xa1c bi\xe1\xbb\x87t gi\xe1...\tformat=\ttext=Xin cho em h\xe1\xbb\x8fi s\xe1\xbb\xb1 kh\xc3\xa1c bi\xe1\xbb\x87t gi\xe1...\ttags=asql,bsql\textra=\tname=\toldquestion=array(72)\tsilent=1\toldtitle=S\xe1\xbb\xb1 kh\xc3\xa1c nhau gi\xe1\xbb\xafa ROUTINES (Trans...\toldcontent=Xin cho em h\xe1\xbb\x8fi s\xe1\xbb\xb1 kh\xc3\xa1c bi\xe1\xbb\x87t gi\xe1...\toldformat=\toldtags=asql,bsql\ttitlechanged=\tcontentchanged=\ttagschanged=')

在我的apache错误日志中。

我该如何解决? 我想我需要配置MySQL排序规则,但我不知道确切的错误。 请帮忙!

1 个答案:

答案 0 :(得分:1)

您需要在查询中使用\转义\\

 INSERT INTO qa_eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) 
   VALUES (NOW(), '10.88.11.123', '52', 'johnanhquan', NULL, 'q_edit', 'postid=913\\ttitle=S\\xe1\\xbb\\xb1 kh\\xc3\\xa1c nhau gi\\xe1\\xbb\\xafa ROUTINES (Trans...\\tcontent=Xin cho em h\\xe1\\xbb\\x8fi s\\xe1\\xbb\\xb1 kh\\xc3\\xa1c bi\\xe1\\xbb\\x87t gi\\xe1...\\tformat=\\ttext=Xin cho em h\\xe1\\xbb\\x8fi s\\xe1\\xbb\\xb1 kh\\xc3\xa1c bi\\xe1\xbb\\x87t gi\xe1...\\ttags=asql,bsql\textra=\tname=\\toldquestion=array(72)\\tsilent=1\\toldtitle=S\\xe1\\xbb\\xb1 kh\\xc3\\xa1c nhau gi\\xe1\xbb\xafa ROUTINES (Trans...\\toldcontent=Xin cho em h\\xe1\\xbb\\x8fi s\\xe1\xbb\\xb1 kh\\xc3\\xa1c bi\\xe1\\xbb\\x87t gi\\xe1...\\toldformat=\\toldtags=asql,bsql\\ttitlechanged=\\tcontentchanged=\\ttagschanged=')

<强> SQL FIDDLE DEMO