1
我有一個函數,從我的郵箱拉電子郵件,並將它們保存在我的數據庫。一切工作正確的95%的查詢,但對於一些失敗,錯誤:一些奇怪的ASCII字符SQL Server查詢失敗
Warning: PDOStatement::execute(): message: Unclosed quotation mark after the character string '
我能夠跟蹤造成問題的字符。它看起來像是其中一個是ASCII 160和ASCII 147的。當我在電子郵件上運行一個簡單的str_replace
時,我能夠正確保存文本而沒有錯誤。爲什麼會導致問題?
$body = $this->get_part($imap, $b, "TEXT/HTML");
if($body == "")
{
$body = $this->get_part($imap, $b, "TEXT/PLAIN");
}
$header = imap_headerinfo($imap, $b);
$subject = $header->subject;
$fromaddress = $header->fromaddress;
/////////////////////////////
$data = array('content'=>$body);
$query = $PDO->prepare('insert into [tbl_test] (content) values (:content)');
$query->execute($data);
break;
跳躍到我腦海的第一件事是編碼不匹配。 – 2013-04-08 13:11:31
的確像一個字符集問題。確保您的php輸入,連接和數據庫設置爲相同。 http://www.theasciicode.com.ar/extended-ascii-code/letter-o-circumflex-accent-o-circumflex-ascii-code-147.html – 2013-04-08 13:11:48
uth8_encode()保存查詢幫助。非常感謝你。 – user1029829 2013-04-08 13:42:23