To align both the character set (e.g., utf8mb4) AND the collation sequence with the schema (database) settings:
<?php
$mysqli = new mysqli( DB_HOST, DB_USER, DB_PASSWORD, DB_SCHEMA, DB_PORT );
if ( 0 !== $mysqli->connect_errno )
throw new \Exception( $mysqli->connect_error, $mysqli->connect_errno );
if ( TRUE !== $mysqli->set_charset( 'utf8mb4' ) )
throw new \Exception( $mysql->error, $mysqli->errno );
if ( TRUE !== $mysqli->query( 'SET collation_connection = @@collation_database;' ) )
throw new \Exception( $mysql->error, $mysqli->errno );
?>
To confirm:
<?php
echo 'character_set_name: ', $mysqli->character_set_name(), '<br />', PHP_EOL;
foreach( $mysqli->query( "SHOW VARIABLES LIKE '%_connection';" )->fetch_all() as $setting )
echo $setting[0], ': ', $setting[1], '<br />', PHP_EOL;
?>
will output something like:
character_set_name: utf8mb4
character_set_connection: utf8mb4
collation_connection: utf8mb4_unicode_520_ci