-2

Ok, I have a web where I consult a database (phpMyAdmin) and display some results (it's basically a searcher). The problem comes when I display results from this Database that have accented characters. The pages in the web are codified in utf-8 and all the content of the web accept accented characters except when I call this database by php. I have also put the collation of the database, the table and the fields on it in ut8-general-ci. I have spent a lot of time finding a solution and it never cames up. I leave the code (in php) when calling the information in the Database:

... 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>"; 
} 
?> 

Please any help will be welcomed.

David Duran
  • 1,786
  • 1
  • 25
  • 36
  • possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through), [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Aug 28 '13 at 19:48

1 Answers1

2

Try using mysql_set_charset after connecting

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

PS

mysql_* functions are deprecated, don't use them. Consider switching to PDO or MySQLi.

user4035
  • 22,508
  • 11
  • 59
  • 94
  • Thank you so much. Everything has been arranged with your line. I owe you one xd. I will take into account the MySQLi advice. – David Duran Aug 28 '13 at 19:57