SQL中的重音字符有问题

时间:2013-08-28 19:45:32

标签: php html mysql

好的,我有一个网络,我咨询数据库(phpMyAdmin)并显示一些结果(它基本上是一个搜索者)。当我显示此数据库中具有重音字符的结果时,问题就出现了。 网页中的页面编码为utf-8,网页的所有内容都接受重音字符,除非我通过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>"; 
} 
?> 

欢迎任何帮助。

1 个答案:

答案 0 :(得分:2)

连接后尝试使用mysql_set_charset

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

PS

不推荐使用

mysql_ *函数,不要使用它们。考虑切换到PDO或MySQLi。

相关问题