2014-02-18 28 views
0

當截斷我有以下查詢:數據條目的MySQL使用%C3特殊字符

INSERT INTO `poll` (`pollId`, `groupId`, `creatorUserId`, `createdDateTime`, 
        `lastVoteDateTime`, `pollQuestion`, `pollOption`) 
       VALUES (NULL, '24', '73', '2014-02-18 21:27:12', '0000-00-00 00:00:00', 
         '1111111111', '222222222222Ã223442') 

當使用PHP爲POLLOPTION插入數據截斷這樣222222222222而不Ã223442執行這個查詢;

但是,當在myManager中執行它時,pollOption的數據成功插入「222222222222Ã223442」;

注意: 數據庫和表和字段都是UTF-8。 PHP文件是ANSI編碼

PHP代碼:

date_default_timezone_set('Asia/Calcutta'); 
require_once "config.php"; 
error_reporting(0); 
$date=date("Y-m-d H:i:s"); 
$response=""; 
if(isset($_REQUEST['userId'])) 
{ 
$userId=$_REQUEST['userId']; 
$groupId=$_REQUEST['groupId']; 
$pollQuestion=$_REQUEST['pollQuestion']; 
$pollOptions=rawurldecode(htmlspecialchars($_REQUEST['pollOptions'])); 

$insertPoll=mysql_query("INSERT INTO `poll` 
        (`pollId`, `groupId`, `creatorUserId`, 
         `createdDateTime`, `lastVoteDateTime`, `pollQuestion`, `pollOption`) 
       VALUES (NULL, '$groupId', '$userId', '$date', '0000-00-00 00:00:00', 
         '$pollQuestion', '$pollOptions')") or die(mysql_error()); 
     echo("INSERT INTO `poll` 
         (`pollId`, `groupId`, `creatorUserId`, `createdDateTime`, 
         `lastVoteDateTime`, `pollQuestion`, `pollOption`) 
         VALUES (NULL, '$groupId', '$userId', '$date', '0000-00-00 00:00:00', 
         $pollQuestion', '$pollOptions')"); 
if($insertPoll) 
{ 
    $response.='{"success":"0","message":"successfully poll posted"}'; 

}else 
{ 
    $response.='{"success":"1","message":"something went wrong"}'; 
} 


echo $response;  

}

回答

0

,一個在你的PHP文件肯定是一個拉丁-1,而不是UTF-8。當提供latin-1擴展字符時,linux mysql會在發現第一個不正確的字符時截斷,而windows mysql會給你一個錯誤。在你的問題的字段

使用函數utf8_encode如果在Latin-1的來臨:

$insertPoll=mysql_query("INSERT INTO `poll` 
        (`pollId`, `groupId`, `creatorUserId`, 
         `createdDateTime`, `lastVoteDateTime`, `pollQuestion`, `pollOption`) 
       VALUES (NULL, '$groupId', '$userId', '$date', '0000-00-00 00:00:00', 
         '$pollQuestion', '".utf8_encode($pollOptions)."')") or die(mysql_error()); 

編輯:調查多一點,誤差不依賴於Linux/Windows的,但是嚴格的模式是否是啓用或不啓用。抱歉!。

無論如何,使用正確的UTF-8將解決您的問題。