我在MySQL中运行它:
SELECT id, action FROM table1 WHERE action in ('α','δ','μ','Α','Δ','Μ')
请注意,字符是希腊语,而且,我到处都使用utf-8。 为什么此查询还返回action ='a'或'A'(拉丁语)??
的行这是整个脚本:
$query = "SELECT id, action FROM table1 WHERE action in ('α','δ','μ','Α','Δ','Μ') ORDER BY id ASC";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$totalRows_result = mysql_num_rows($result);
if($totalRows_result > 0) {
do {
$str = $row['action'];
$greek = array('α','δ','μ','Α','Δ','Μ');
$latin = array('A','D','M','A','D','M');
$validstr = str_replace($greek, $latin, $str);
$q = "UPDATE table1 SET action='$validstr' WHERE id='".$row['id']."'";
$res = mysql_query($q) or die(mysql_error());
} while ($row = mysql_fetch_assoc($result));
}
答案 0 :(得分:0)
尝试以下方法:
连接到mysql后,执行此查询以确保您使用的是UTF8:
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
或看看这是否可以帮助你
<?php header("Content-type: text/html; charset=utf-8"); ?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
你可以试试这个
<?php
$link1 = mysql_connect('localhost','user1','pass1',TRUE);
mysql_selectdb('db1',$link1);
mysql_set_charset('utf8',$link1);
?>
答案 1 :(得分:0)
使用mysql_set_charset('utf8');