Tuesday 2 June 2015

Alter all tables in database

<?php
/* 
your connection goes here, example:
mysql_connect("localhost","root","***");
mysql_select_db("db1");
*/

// convert code
$res = mysql_query("SHOW TABLES");
while ($row = mysql_fetch_array($res))
{
    foreach ($row as $key => $table)
    {
        mysql_query("ALTER TABLE " . $table . " CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci");
        echo $key . " - " . $table . " - CONVERTED<br />";
    }
}
?>
 

Usage

Change the 'ALTER' SQL syntax to whatever specific operation you need to perform on your database
 

0 comments:

Post a Comment