How can the SQL command "SET NAMES 'UTF-8'" be utilized in PHP to avoid character encoding issues?

When working with a database in PHP, it is important to ensure that the character encoding is set correctly to avoid any issues with special characters or non-ASCII characters. One way to do this is by using the SQL command "SET NAMES 'UTF-8'" to specify the character encoding as UTF-8, which is a widely supported encoding for handling various languages and characters.

// Establish a connection to the database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Set the character encoding to UTF-8
$mysqli->query("SET NAMES 'UTF-8'");