Created
September 19, 2016 08:35
-
-
Save uprise10/f9a6eb302db6884034fe8235ae49a65f to your computer and use it in GitHub Desktop.
Change DB collation of all tables and columns
This file contains hidden or 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 | |
$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