What are best practices for ensuring consistent character encoding across PHP files and database interactions?

In order to ensure consistent character encoding across PHP files and database interactions, it is important to set the character encoding for both the PHP files and the database to UTF-8. This can be achieved by setting the appropriate headers in PHP files and configuring the database to use UTF-8 encoding for tables and columns.

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

// Set character encoding for database interactions
$pdo = new PDO('mysql:host=localhost;dbname=my_database', 'username', 'password');
$pdo->exec("set names utf8");