Question : mysql returning question mark squares instead of special characters

When making a MySQL query in php the database returns boxed question marks instead of special characters like ' " æ ø å etc.

1. Tried to alter charset in html page
2. Tried to alter the charcter set in MySQL table
3. Tried the mysql_real_escape_string() function

None of these worked.

I read somewhere that the db connection needs to be set to utf-8, but I'm not sure how to do that?

Has anyone a solution to this problem?

thank you!
Code Snippet:
1:
2:
3:
4:
//connection snippet. Login-info removed for security
 
$link = mysql_connect("host", "username", "password") or die("Could not connect : " . mysql_error());
mysql_select_db("dbname") or die("Could not select database");
Open in New Window Select All

Answer : mysql returning question mark squares instead of special characters

The following articles will be useful http://dev.mysql.com/doc/refman/5.0/en/charset-syntax.html and http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html

After you connect to the database issue the following command:

SET NAMES 'utf8';

Ensure that your web page also uses the UTF-8 encoding:



PHP also offers several function that will be useful for conversions:

http://us3.php.net/manual/en/function.iconv.php
http://us.php.net/mb_convert_encoding
Random Solutions  
 
programming4us programming4us