Skip to content

Instantly share code, notes, and snippets.

@tanmay27vats
Created January 21, 2018 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tanmay27vats/6c0f317c2d41006f71a0ee01e1073c5c to your computer and use it in GitHub Desktop.
Save tanmay27vats/6c0f317c2d41006f71a0ee01e1073c5c to your computer and use it in GitHub Desktop.
Change collation to utf8 of all tables of database
$dbname=’db’; //your database name
$username=’userrname’; // your database user name
$password=’password’; //your database user password
$db = mysql_connect($dbname,$username,$password);
if (!$db) {
echo "Cannot connect to the database – incorrect details";
} else {
mysql_select_db(‘pm’);
$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!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment