After installing php7 through epel source, connect to the database and directly prompt:
<code>Unable to set client connection character set: utf8mb4</code>
No error is reported when using utf8
Find a solution: directly use the sql statement to set the character set
<code>SET NAMES 'utf8mb4';</code>
But it always feels bad to use this method, and there are many places that need to be changed in the previous code, which is a bit uneconomical
Hey guys, do you have a solution? Thanks in advance
PS: I couldn’t find a solution after searching on Google for a whole day, but it’s probably a silly problem
================================================== =================
The cause of the problem was found, and it turned out to be just a configuration problem
<code>$pdo = new PDO('mysql:host=localhost;dbname=my_db;charset=utf8mb4', 'db_user', 'db_password');</code>
to:
<code>$pdo = new PDO('mysql:host=localhost;dbname=my_db', 'db_user', 'db_password', array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', ));</code>
I don’t know why the new version of the pdo driver cannot directly set the connection character set to utf8mb4
. Logically speaking, it should be backward compatible, but at least a solution has been found :-D
After installing php7 through epel source, connect to the database and directly prompt:
<code>Unable to set client connection character set: utf8mb4</code>
No error is reported when using utf8
Find a solution: directly use the sql statement to set the character set
<code>SET NAMES 'utf8mb4';</code>
But it always feels bad to use this method, and there are many places that need to be changed in the previous code, which is a bit uneconomical
Hey guys, do you have a solution? Thanks in advance
PS: I couldn’t find a solution after searching on Google for a whole day, but it’s probably a silly problem
================================================== =================
The cause of the problem was found, and it turned out to be just a configuration problem
<code>$pdo = new PDO('mysql:host=localhost;dbname=my_db;charset=utf8mb4', 'db_user', 'db_password');</code>
to:
<code>$pdo = new PDO('mysql:host=localhost;dbname=my_db', 'db_user', 'db_password', array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', ));</code>
I don’t know why the new version of the pdo driver cannot directly set the connection character set to utf8mb4
. Logically speaking, it should be backward compatible, but at least a solution has been found :-D