Changing the collation for all tables in a MySQL database can be time consuming depending on how many tables you have. An easier and less time consuming way is the following PHP script that changes the collation for all tables at a time:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<?php
$db = mysql_connect('localhost','myuser_mydbuser','mypassword');
if(!$db) echo "Cannot connect to the database - incorrect details";
mysql_select_db('myuser_mydbname'); $result=mysql_query('show tables');
while($tables = mysql_fetch_array($result)) {
foreach ($tables as $key => $value) {
mysql_query("ALTER TABLE $value COLLATE utf8_general_ci");
}}
echo "The collation of your database has been successfully changed!";
?> |
Make sure to substitute in the [...]