How can the collation of a database table be changed to UTF-8 to support proper character encoding in PHP?

To change the collation of a database table to UTF-8 in PHP, you can use SQL queries to alter the table and set the character set to utf8. This will ensure proper character encoding for storing and retrieving data in the database.

<?php
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Change collation of table to UTF-8
$sql = "ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci";
$conn->query($sql);

// Close the connection
$conn->close();
?>