Skip to content

Instantly share code, notes, and snippets.

@uprise10
Created September 19, 2016 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uprise10/f9a6eb302db6884034fe8235ae49a65f to your computer and use it in GitHub Desktop.
Save uprise10/f9a6eb302db6884034fe8235ae49a65f to your computer and use it in GitHub Desktop.
Change DB collation of all tables and columns
<?php
$database_name='';
$database_username='';
$database_password='';
$connection = mysqli_connect('localhost',$database_username,$database_password);
if(!$connection) {
echo "Cannot connect to the database – incorrect details";
} else{
mysqli_select_db($connection, $database_name);
$result=mysqli_query($connection, 'show tables');
while($tables = mysqli_fetch_array($result)) {
foreach ($tables as $key => $value) {
//echo "ALTER TABLE ".$value." CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci<br>";
mysqli_query( $connection, "ALTER TABLE ".$value." CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
}
}
echo "Successfull collation change!";
}
mysqli_close($connection);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment