0

我在 MySQL 中运行它:

SELECT id, action FROM table1 WHERE action in ('α','δ','μ','Α','Δ','Μ')

请注意,这些字符是希腊语,而且我到处都在使用 utf-8。为什么此查询还返回 action = 'a' 或 'A' (latin) 的行?

这是整个脚本:

$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));
    }
4

2 回答 2

0

利用mysql_set_charset('utf8');

于 2013-05-10T16:12:20.133 回答
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); 
?>
于 2013-05-10T15:36:55.707 回答