Are there any best practices for handling special characters like "ö" and "ä" in PHP code when interacting with a database?

Special characters like "ö" and "ä" can cause issues when interacting with a database if the character encoding is not set correctly. To handle these special characters properly, it is important to ensure that the character encoding is set to UTF-8 for both the database connection and the PHP script.

// Set the character encoding for the database connection
mysqli_set_charset($connection, 'utf8');

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