What are the recommended methods for setting character encoding in PHP MySQL connections to avoid issues with special characters?

Special characters can cause issues in PHP MySQL connections if the character encoding is not set correctly. To avoid problems with special characters, it is recommended to set the character encoding to UTF-8 in both PHP and MySQL connections. This ensures that special characters are properly handled and displayed.

// Set character encoding for PHP
mysqli_set_charset($conn, 'utf8');

// Set character encoding for MySQL
$conn->set_charset('utf8');