Created
July 7, 2015 11:22
-
-
Save iammart/0b92957256cd2e7cfd0d to your computer and use it in GitHub Desktop.
Issues with phonetical characters in the database. This script will alter the tables and database to the correct character set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$char_set = 'utf8'; | |
// Adds the header information | |
header('Content-type: text/plain'); | |
// Runs the SQL query on teh database | |
$sql = 'SHOW TABLES'; $result = mysql_query($sql) or die( mysql_error() ); | |
// Runs a loop that finds all collations within the database and changes it to the new collation | |
while ( $row = mysql_fetch_row($result) ) : | |
$table = mysql_real_escape_string($row[0]); | |
$sql = "ALTER TABLE {$table }CONVERT TO CHARACTER SET {$char_set} COLLATE utf8_general_ci"; | |
mysql_query($sql) or die( mysql_error() ); | |
print "{$table} changed successfully.\n"; | |
endwhile; | |
// Update the Collation of the database itself | |
$sql = "ALTER DATABASE CHARACTER SET {$char_set};"; | |
mysql_query($sql) or die( mysql_error()); | |
print "Database collation has been updated successfully.\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment