Wednesday, April 10, 2013

How to change the collation for all tables in a MySQL database to UTF-8 through cpanel?

create script and execute it on the server

$connection = mysql_connect(‘localhost’,$database_username,$database_password);
if(!$connection) {
    echo “Cannot connect to the database – incorrect details”;
$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”);
echo “Successfull collation change!”;
 edit the lines as follows:
$database_name – the actual name of the database.  cpanelusername_databasename
$database_username – the username which have privilleges to operate with certain database.
$database_password – the actual password for the above used username

No comments:

Post a Comment