I am trying to set a very simple session connection variable on MySQL, but it doesn't do anything. The queries run below do not cause any errors, but the character set of the MySQL connection won't be changed. If I configure the default values for 'collation_server' and 'character_set_server' in the my.ini file as utf8mb4 instead of latin1, then the character set becomes utf8mb4, but I wonder why I cannot change the connection character set from my PHP script.
$pdo = new \PDO("mysql:host=localhost", "root", "");
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$pdo->query("SET NAMES utf8mb4");
print_r($pdo->query("SHOW GLOBAL VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';")->fetchAll(PDO::FETCH_ASSOC));
This query shows that the SET NAMES statement did not have affect.