I am trying to access a localhost database via PHP and MySQL. Every time I try, I get the error: Warning: PDO::__construct(): Server sent charset (255) unknown to the client.
Within the error message I see that I am calling:
PDO->__construct('mysql:host=localhost;dbname=db;charset=utf8mb4', 'noah', 'mypassword').
Everything that I've looked up so far has told me that the problem has to do the character sets not matching between my call and the database. However, when I log into MySQL via mysql -u noah -p
, do USE db
and then SELECT @@character_set_database, @@collation_database;
I see:
+--------------------------+----------------------+
| @@character_set_database | @@collation_database |
+--------------------------+----------------------+
| utf8mb4 | utf8mb4_unicode_ci |
+--------------------------+----------------------+
So they are using the same character set and I really don't know why the query isn't working. To make things weirder, when I change the database user or password that the constructor is called with, I get the same error. I would expect it to give me a different error about bad login credentials. But if I change the dsn, it does give me a different error about how it can't find the database.
I am using MySQL 8.0.17 and running the code via a local development server with google app engine. That dev server is running PHP 5.5.26
EDIT: Here is some of the actual code at the source of the problem:
$app['db'] = function (Container $c) {
$pdo = new ExtendedPDO(
$c['service.config']->get('db.dsn'),
$c['service.config']->get('db.user'),
$c['service.config']->get('db.password')
);
Container is a Pimple container. App is a Silex application. ExtendedPDO is just a class that has extended PDO in ways that are unimportant here (it just keeps track of a query count while calling parent functions). All the db fields are grabbed from a env_dev.yaml file, and I know this to be true because when I change them there it changes the output of the error message. The error message traces back to the last line of the code block posted above, because on trying to create the PDO object it releases the exception.