How can the connection to a database be adjusted to support UTF-8 encoding in PHP?

To adjust the connection to a database to support UTF-8 encoding in PHP, you can set the character set to UTF-8 when establishing the connection. This ensures that data retrieved from the database will be properly encoded in UTF-8.

// Establish connection to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

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

// Set the character set to UTF-8
$conn->set_charset("utf8");

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}