How can one avoid issues when working with Unicode files in PHP and MySQL?

Issue: When working with Unicode files in PHP and MySQL, it's essential to ensure that both the PHP script and the MySQL database are set up to handle Unicode characters properly. To avoid issues, make sure to set the character encoding to UTF-8 in both PHP and MySQL. PHP Code Snippet:

// Set UTF-8 encoding for PHP
header('Content-Type: text/html; charset=utf-8');
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');

// Set UTF-8 encoding for MySQL connection
$mysqli = new mysqli('localhost', 'username', 'password', 'database');
$mysqli->set_charset('utf8');