$ary['Type'] = trim($ary['Type']); if (preg_match("#^varchar#", $ary['Type'])) { return true; } if (preg_match("#^text#", $ary['Type'])) { return true; } if (preg_match("#^mediumtext#", $ary['Type'])) { return true; } if (preg_match("#^longtext#", $ary['Type'])) { return true; } if (preg_match("#^tinytext#", $ary['Type'])) { return true; } return false; } $tables = get_tables_db(); foreach ($tables as $table) { $create = get_table_create($table); foreach ($create as $column) { if (column_has_text($column)) { echo "Fixing {$table}: column {$column['Field']}\n"; $query = "ALTER TABLE `{$table}` MODIFY `{$column['Field']}` {$column['Type']} character set latin1;"; $query .= "ALTER TABLE `{$table}` MODIFY `{$column['Field']}` BLOB;"; $query .= "ALTER TABLE `{$table}` MODIFY `{$column['Field']}` {$column['Type']} character set utf8;"; $db->rawQuery($query); } } }
/** * clone a complete database * @param string $database * @param string $newDatabase * @return boolean $res */ public static function cloneDB($database, $newDatabase) { $db = new db(); $rows = $db->selectQuery('show tables'); $tables = array(); foreach ($rows as $table) { $tables[] = array_pop($table); } $db->rawQuery("CREATE DATABASE `{$newDatabase}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"); foreach ($tables as $cTable) { self::changeDB($newDatabase); $create = $db->rawQuery("CREATE TABLE {$cTable} LIKE " . $database . "." . $cTable); if (!$create) { $error = true; } $db->rawQuery("INSERT INTO {$cTable} SELECT * FROM " . $database . "." . $cTable); } return !isset($error) ? true : false; }