What are the best practices for setting the character encoding in PHP when working with databases?

When working with databases in PHP, it is important to ensure that the character encoding is properly set to avoid any issues with special characters or language-specific characters. The best practice is to set the character encoding to UTF-8, which supports a wide range of characters and is commonly used for internationalization.

// Set character encoding to UTF-8
mysqli_set_charset($connection, "utf8");