-2

好的,我有一个网站,我可以在其中查阅数据库(phpMyAdmin)并显示一些结果(它基本上是一个搜索器)。当我显示此数据库中带有重音字符的结果时,问题就出现了。Web 中的页面以 utf-8 编码,并且 Web 的所有内容都接受重音字符,除非我通过 php 调用此数据库。我还把数据库、表和字段的排序规则放在了ut8-general-ci中。我花了很多时间寻找解决方案,但从未出现过。调用数据库中的信息时,我留下代码(在 php 中):

... some code



//We select the webs with the same keywords (coincidences). 
//We order first the search in the same language. All ordered by Title.
$result = mysql_query("SELECT * FROM Webs WHERE Keywords LIKE '%$search%' ORDER BY CASE WHEN Language='English' THEN 0 ELSE 1 END, Title", $link);

if ($row = mysql_fetch_array($result))
{ 
//We start the list of results
echo "<ul>"; 
  do 
  {
      //One list element
      echo "<li>"; 
      echo "<a href=http://".$row["Url"].".html><b>".$row["Title"]."</b></a><br/>"; 
      echo "<a href=http://".$row["Url"].".html>".$row["Url"]."</a><br/>"; 
      echo "".$row["Description"]."<br/>"; 
      echo "</li><br/>"; 
    } 
    while ($row = mysql_fetch_array($result)); 

    //We end the list of results
    echo "</ul><br/>"; 
} 
else 
{ 
    echo "<p>No register has been found !</p>"; 
} 
?> 

欢迎任何帮助。

4

1 回答 1

2

连接后尝试使用mysql_set_charset

$connect = mysql_connect('localhost', $user, $password);
mysql_set_charset('utf8', $connect);

附言

mysql_* 函数已弃用,请勿使用它们。考虑切换到 PDO 或 MySQLi。

于 2013-08-28T19:50:21.200 回答