2015-04-21 119 views
3

我有表:當我嘗試插入參數插入數據庫查詢失敗?

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

您需要在查詢中用\\轉義\

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