• 11Dec

    /**
    * DB Connection
    * …
    */

    $result = mysql_query(”SHOW TABLES;”);
    $rows = mysql_num_rows($result);
    if ($rows) {
    while ($item = mysql_fetch_array($result)) {
    mysql_query(”ALTER TABLE {$item[0]} DEFAULT CHARACTER SET utf8 COLLATE utf8_turkish_ci”);
    $sub = mysql_query(”SHOW FIELDS IN {$item[0]}”);
    $nums = mysql_num_rows($sub);
    if ($nums) {
    while ($field = mysql_fetch_array($sub)) {
    if (substr_count($field['Type'], ‘char’) or substr_count($field['Type'], ‘enum’)) {
    if (trim($field['Null']) == ‘YES’) $nn = null;
    else $nn = “NOT NULL”;

    if (trim($field['Default'])) $df = ‘DEFAULT = ‘ . $field['Default'];
    else $df = null;

    mysql_query(”ALTER TABLE $item[0] CHANGE {$field['Field']} {$field['Field']} {$field['Type']} $df CHARACTER SET utf8 COLLATE utf8_turkish_ci $nn”);
    } } } } }

    Note: You may need some modifications. Please check the code right before you run it!