Multi-language applications and UTF-8 databases

By default, the databases on SiteGround's servers are created with latin1_swedish_ci collation. This may cause some issues if you use your application with languages with non-standard characters (Cyrillic, Chinese, etc.).

Therefore, the best practice prior to installing your application is to modify your database to use UTF-8 collation first. This can be done through the phpMyAdmin tool in your cPanel. Once you have loaded it, you should select your database and click on the Operations tab on the top of the screen. Then select utf8_general_ci from the "Collation" drop-down menu and click on the "Go" button.

Next, you can proceed with installing your application, using the newly created database.

You can repeat the same steps for modifying the database of already installed applications. This, however, will change the collation only for the newly added data and may not be enough for your application to work properly. Therefore, you can create a PHP file (you can call it whatever you wish, e.g. collation.php) in your public_html folder with the following content:

<?php
$db = mysql_connect('localhost','USERNAME','PASSWORD');
if(!$db)
echo "cannot connect to the database";
mysql_select_db('DATABASE');
$result=mysql_query('show tables');
while($tables = mysql_fetch_array($result)) {
foreach ($tables as $key => $value) {
mysql_query("ALTER TABLE $value COLLATE utf8_general_ci");
}
}
?>

You should make sure you add the correct data into the USERNAME, PASSWORD and DATABASE variables. Next, just call the newly created file, and it will change the collation of all the existing fields to utf8_general_ci.

For most web applications this should be enough for them to start working correctly with the new encoding. However, some scripts may still malfunction. Unfortunately, in such cases you have to create a new database, change its collation and re-install your application with it.

cPanel is easy to work with when you have the right host to support you. If you need a reliable partner to help you manage your website with cPanel, check out our cPanel hosting services!

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to export/import a MySQL database via SSH

In this article we will show you how to export and import a MySQL database via SSH. Managing your...

Error about legacy type authentication (old-style) when connecting remotely to MySQL

This particular error can occur in some MySQL clients. The reason for it is that our servers...

How to change the password of a Mysql user in cPanel?

If you have already created a MySQL user through the cPanel -> Mysql Databases tool you may...

How to reset the password for a MySQL database?

You may need to change the password of your database in order to improve the security of your...

I cannot create views in MySQL

Regular MySQL users do not have privileges to create views in MySQL. If you try to execute CREATE...