To change the collation of a MySQL database in PHP, follow the steps below:
Connect to the MySQL database using PHP mysqli_connect() function.
main.php73 chars2 lines
Run the SQL query to change the collation of the database.
main.php102 chars2 lines
Replace database_name
with the name of the database that you want to change the collation for.
The above query changes the collation of the database to utf8mb4
with utf8mb4_unicode_ci
which is a general-purpose collation that is case-insensitive and accent-insensitive.
Close the database connection using mysqli_close() function.
main.php21 chars2 lines
That's it! The collation of the database has been changed using PHP.
gistlibby LogSnag