PHP Code:
#########################################################################
#########################################################################
## ##
## Script coded by Eric Reiche ##
## ##
## Version: 0.2 / 2006-08-16 17:35 GMT + 100 ##
## Version 0.2 contains bugfixes ##
## ##
## Inspired by serversupportforum.de user monotek ##
## ( [url="http://www.serversupportforum.de/forum/sql/"]http://www.serversupportforum.de/forum/sql/[/url] \ ##
## 9279-kollation-von-tabellen-aendern.html#post67293 ) ##
## [Check link for bashscript] ##
## ##
## Web: [url="http://www.ericreiche.net"]http://www.ericreiche.net[/url] || Mail: [email]webmaster@ericreiche.net[/email] ##
## ##
## You can spread this script, until you don't touch this copymark ##
## ##
#########################################################################
#########################################################################
//Config:
$mysqlserver = 'localhost'; //Host
$mysqluser = 'root'; //User [It's recomment to use root]
$mysqlpw = 'passwort'; //Password
$mysqldb = 'datenbank'; //Database
$stepping = 100; //Queries per Page
$tabletoskip = 'really_big_table'; //If you have a really big table, you can enter it here,
//it will be skipped, to prevent a script abort
$collation = 'latin1_german2_ci';
$character_set = 'latin1'; //End Config
#######################################################################
# Do not change anything from here, until you know what you're doing #
#######################################################################
if(isset($_GET['start']) && is_numeric($_GET['start'])){
$start = $_GET['start'];
if($start > 0){
$start = $start * $stepping;
}
}else{
$start = 0;
} //mysql connect @mysql_connect($mysqlserver, $mysqluser, $mysqlpw) OR die("No Conncection to Server. Report: :".mysql_error()); mysql_select_db($mysqldb) OR die("couldn't select database, Report: ".mysql_error());
unset($mysqlserver);
unset($mysqluser);
unset($mysqlpw);
$i = 0;
print('');
if($start == 0){
$sql = 'ALTER DATABASE '.$mysqldb.' DEFAULT CHARACTER SET '.$character_set.' COLLATE '.$collation.";\r\n";
mysql_query($sql);
print($sql);
}
$sql = 'Show tables;'; $result1 = mysql_query($sql);
while($tables = mysql_fetch_assoc($result1)){
if($start == 0){
$sql = 'ALTER TABLE '.$tables['Tables_in_'.$mysqldb].' DEFAULT CHARACTER SET '.$character_set.' COLLATE '.$collation.";\r\n";
mysql_query($sql);
print(''.$sql);
}
$sql = 'Show columns FROM '.$tables['Tables_in_'.$mysqldb];
$result2 = mysql_query($sql);
while($columns = mysql_fetch_assoc($result2)){
if(substr_count($columns['Type'], 'varchar') || substr_count($columns['Type'], 'text')){
$i++;
if($i >= $start && $i < ($start + $stepping)){
$sql = 'ALTER TABLE '.$tables['Tables_in_'.$mysqldb].' CHANGE '.$columns['Field'].' '.$columns['Field'].' '.$columns['Type'].' CHARACTER SET '.$character_set.' COLLATE '.$collation.';';
if($tabletoskip != $tables['Tables_in_'.$mysqldb]){
mysql_query($sql);
print(''.$i.'. '.$sql."\r\n");
}else{
print(''.$i.'. SKIPPED: '.$sql."\r\n");
}
}
}
}
}
print('
');
print('.$_SERVER['PHP_SELF'].'?start='.($_GET['start'] + 1).'">Weiter...');
?>
No comments:
Post a Comment