You cannot convert a whole database with a simple iconv, neither with PHP library nor with commandline tool. If your database contains binary data, it will be corrupted.
There are plenty of postings in the WWW about converting database from latin1 to utf8, simply enter "how to convert mysql database from latin1 to utf8" into Google. I found some very handy scripts which basically are using mysqldump (which knows the table structures of your database, what iconv does not know) to export the database into the desired format.
P.S.: I just found this sneaky solution, i did not test it, but it looks very simple. Open phpmyadmin or run mysql and enter this SQL Statement:
- Code: Select all
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
I dont know if this really converts all characters to utf8 (or if it only changes the datatype, without changing the data) but its definately worth a try! DONT FORGET TO BACKUP YOUR DATA BEFORE RUNNING ANYTHING!!!
P.P.S.: Just found out, that the above ALTER does NOT convert any characters. You have to convert the tables by using ALTER TABLE ... CONVERT:
- Code: Select all
ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
Here is a very usefull posting, which shows everything you need:
https://stackoverflow.com/questions/611 ... n-to-utf-8There is also a shell script shown, which automatically loops over all the tables of a database and runs the CONVERT of the character:
- Code: Select all
DB="dbname"
(
echo 'ALTER DATABASE `'"$DB"'` CHARACTER SET utf8 COLLATE utf8_general_ci;'
mysql "$DB" -e "SHOW TABLES" --batch --skip-column-names \
| xargs -I{} echo 'ALTER TABLE `'{}'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;'
) \
| mysql "$DB"
Or, in one line:
- Code: Select all
DB="dbname"; ( echo 'ALTER DATABASE `'"$DB"'` CHARACTER SET utf8 COLLATE utf8_general_ci;'; mysql "$DB" -e "SHOW TABLES" --batch --skip-column-names | xargs -I{} echo 'ALTER TABLE `'{}'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' ) | mysql "$DB"