What best practices should be followed to ensure consistent character encoding in PHP files and databases?

To ensure consistent character encoding in PHP files and databases, it is important to set the character encoding for both the PHP files and the database to UTF-8. This will ensure that special characters and symbols are displayed correctly across different platforms and browsers.

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

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