[TYPO3] cscript onvert database to utf8

Alexander Heidl aheidl at fulcio.co.uk
Fri Nov 24 20:26:11 CET 2006


Here is my little php shell script to set the tables of an existing 
database from whatever to utf-8:

#!/path/to/php
<?php
mysql_connect('DB_HOST', 'DB_USERNAME', 'DB_PASSWORD')
    or die('Could not connect: ' . mysql_error());
echo 'Connected successfully\n';
mysql_select_db('DB_NAME') or die('Could not select database');

$sql = mysql_query('show tables');
while($tables = mysql_fetch_row($sql)) {
   echo "Table: {$tables[0]}\n";
   $query = "ALTER TABLE ".$tables[0]." DEFAULT CHARACTER SET utf8 
COLLATE utf8_general_ci";
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   echo $query . " = " . $result . "\n";
}
?>

I couldn't be bothered doing it all by hand and I got tired of searching 
for an solution. This did the trick for me. However. some field 
collations still remain as they were. I am not sure if that should 
bother me, but so far no strange behavior cold be recognized.

So, please feel free to use the script if are interested. Though bear in 
mind to backup your DB before!!! And also the usual bladibla about 
adapting the script to your needs before it will work ;)

cherio,

Alex
www.dental-offer.com




More information about the TYPO3-english mailing list