Skip to content

Instantly share code, notes, and snippets.

@woraperth
Last active September 23, 2015 18:34
Show Gist options
  • Save woraperth/68db2df9669d801ca06c to your computer and use it in GitHub Desktop.
Save woraperth/68db2df9669d801ca06c to your computer and use it in GitHub Desktop.
<?php
/* Original Script from: http://stackoverflow.com/questions/1294117/how-to-change-collation-of-database-table-column */
/* Note: This script will loop through all the tables and change collation to utf8_general_ci
But it will not change database's collation. The only way to change database collation might be to delete and create it again.
/*
$con = mysql_connect('localhost','db_user','db_pass'); /* Edit DB Username / Password */
if(!$con) { echo "Cannot connect to the database ";die();}
mysql_select_db('db_name'); /* Edit DB Name */
$result=mysql_query('show tables');
while($tables = mysql_fetch_array($result)) {
foreach ($tables as $key => $value) {
mysql_query("ALTER TABLE $value CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci"); /* Edit target DB Collation */
}}
echo "The collation of your database has been successfully changed!";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment