<?
#########################################################################
#########################################################################
## ##
## 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 ##
## ( http://www.serversupportforum.de/forum/sql/ \ ##
## 9279-kollation-von-tabellen-aendern.html#post67293 ) ##
## [Check link for bashscript] ##
## ##
## Web: http://www.ericreiche.net || Mail: mail [AT] ericreiche [DOT] net ##
## ##
## You can spread this script, as long as you don't touch this copymark ##
## ##
#########################################################################
#########################################################################
//Config:
$mysqlserver = 'localhost'; //Host
$mysqluser = 'root'; //User [It's recommended 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('<pre>');
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.'. <b>SKIPPED</b>: '.$sql."\r\n");
}
}
}
}
}
print('</pre>');
print('<a href="'.$_SERVER['PHP_SELF'].'?start='.($_GET['start'] + 1).'">Weiter...</a>');
?>