Is the "SET NAMES" command persistent until it is overwritten by another "SET NAMES" command in PHP?

The "SET NAMES" command in PHP is not persistent and needs to be executed every time a new database connection is established to ensure the correct character set is used. To solve this issue, you can create a function that sets the character set for each new database connection.

function setDatabaseCharset($connection, $charset){
    mysqli_set_charset($connection, $charset);
}

// Example of setting the character set for a new database connection
$mysqli = new mysqli('localhost', 'username', 'password', 'database');
setDatabaseCharset($mysqli, 'utf8');