我試圖從一個表,其整理爲「utf8_general_ci」和題爲「APP_NAME」的列中檢索數據的Unicode字符字符串具有這樣的:植物大戰殭屍™2,포코팡爲Kakao,네이버 - Naver,μTorrent® - Torrent App。當我試圖查詢表如下:編碼一個MySQL輸出
<?php
$con = mysql_connect('localhost', 'root', 'root') or die('Error connecting to server');
mysql_select_db('googleappanalysis', $con);
if(isset($_POST['appType']))
{
$appType = $_POST['appType'];
$month = $_POST['month'];
$year = $_POST['year'];
}
$monthYear = $month.$year;
mysql_query("SET NAMES utf8")
if($appType == "Apps with IA"){
$sql="SELECT app_name FROM MonthlyAppState WHERE is86 = 1 AND is86 IS NOT NULL AND monthYear = '".$monthYear."'";
$result=mysql_query($sql);
}elseif($appType == "Apps with no IA"){
$sql="SELECT app_name FROM MonthlyAppState WHERE is86 = 0 AND is86 IS NOT NULL AND monthYear = '".$monthYear."'";
$result=mysql_query($sql);
}
$table = array();
$table['cols'] = array(
array('label' => $appType, 'type' => 'string')
);
$rows = array();
$appendingString = "";
while($r = mysql_fetch_assoc($result)){
$temp = array();
$temp[] = array('v' => (string)$r['app_name']);
$rows[] = array('c' => $temp);
$appendingString = $appendingString."/".$r['app_name'];
}
$myFile = "logfile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $appendingString);
fclose($fh);
$table['rows'] = $rows;
// encode the table as JSON
$jsonTable = json_encode($table);
// set up header; first two prevent IE from caching queries
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo $jsonTable;
?>
的jsontable拋出空值和文件「logfile.txt'the Unicode字符被轉換爲‘???’如圖here
你真的應該避免使用MySQL的,而是使用類似的mysqli或PDO。它使保護自己免受SQL注入平凡而普通的mysql類消毒您查詢的負擔總是落在你,而不是你的技術。 – echochamber
什麼是你從選擇列的字符集(不整理)? – zerkms
其UTF8 APP_NAME的 –