1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Preventing issues with special characters and page encoding issues
For example, if the coding scheme used for the HTML page is UTF8 whereas the database uses Latin-1, accents will not be properly interpreted by MySQL. If pages contain special characters (text in Arabic or Chinese, accents) then such characters may display correctly on your site, but not in phpMyAdmin or vice versa...
Actions to be carried out
In order to ensure that everything works correctly, you MUST specify the charset used in all places (UTF8 for the sake of simplicity).
Use a text editor that is able to save your files in UTF8. If you import text files containing SQL, these must be edited with an editor that saves in UTF8.
Force your site's headers to UTF8 using the following PHP function:
header('Content-Type: text/html; charset=utf-8');
Add the following to your HTML meta tags:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
Declare your database and tables to use UTF8 encoding in PHPMyAdmin (e.g. utf8_general_ci)
Add the following lines to the .htaccess file within your /web folder:
php_value default_charset utf-8
php_value mbstring.internal_encoding UTF-8
Add the PHP function mysql_set_charset when connecting via mysql_connect in order to specify the encoding used for this connection (if you do not specify an encoding, the default value for this parameter may vary from server to server):
]$connection = mysql_connect($server, $username, $password);
You may also change the default setting across your entire hosting space by following the instructions in this documentation.
Once a MySQL connection has been established from a PHP script, you may also specify the UTF8 charset via the following commands:
mysql_query("SET NAMES 'utf8';");
mysql_query("SET CHARACTER SET 'utf8';");
Link to this FAQ: