Search code examples
phputf-8decodeencode

utf8_general_ci causes broken characters


$sql = "SELECT bdId, bdTitle FROM board"; 
$result = dbQuery($sql);    
            for($i = 0; $i < 4; $i++)
            {   
                $row = dbFetchAssoc($result);
                $newsId = $row['bdId'];
                echo '<li><a href="index.php?view=detailedNews&newsId=' . '$newsId">' .$row['bdTitle'] . '</li>';
            }

I'm trying to echo non-english text from 'bdTitle' column which is stored as utf8_general_ci. However, that codes gives me bunch of questions marks like ' ????? . ????.?????? ' What's the problem here and how can I print the texts properly?


Solution

  • set utf-8 encoding for your database connection

    $link = mysql_connect('localhost','user','pass'); 
    
    mysql_set_charset('utf8',$link);