What are the best practices for configuring PHP and MySQL to avoid errors related to character sets and paths?

When configuring PHP and MySQL, it is important to ensure that both systems are using the same character set to avoid errors related to encoding and displaying text properly. Additionally, setting the correct file paths for database connections and other resources is crucial for smooth operation of the application.

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

// Set default character set for PHP
ini_set('default_charset', 'UTF-8');

// Set file paths for database connection
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_NAME', 'database');