I'm working against a database that is using UTF8 encoding and has many user names that contain special characters, such as "Ғђ ▫ Sony"
When querying the user table, Lumen responds with incorrect data. I've tried querying the same table using mysqli
and PDO
and I receive the expected results. I set up a sample route to test it:
$app->get("charset", function() {
$mysqli = new mysqli("localhost", "user", "password", "database");
$res = $mysqli->query("select name from users where id = 1");
$dbh = new PDO('mysql:host=localhost;dbname=database', "user", "password");
$stmt = $dbh->query("select name from users where id = 1");
$lumen = DB::select("select name from users where id = 1");
return response()->json([
"mysqli" => $res->fetch_assoc(),
"pdo" => $stmt->fetchAll(PDO::FETCH_ASSOC),
"framework" => $lumen
]);
});
When accessing the route, I get the following response:
{
"mysqli": {
"name": "Ғђ ▫ Sony"
},
"pdo": [
{
"name": "Ғђ ▫ Sony"
}
],
"framework": [
{
"name": "Ò’Ñ’ â–« Sony"
}
]
}
Here's a screenshot of the response in case the text above does not display correctly:
As far as I can tell, Lumen's MySQL config defaults to UTF8 and is unchangeable - I found the following in vendor/laravel/lumen-framework/config/database
:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => env('DB_PREFIX', ''),
'timezone' => env('DB_TIMEZONE','+00:00'),
'strict' => false,
],
I'm at a loss as to what could be causing this. What else can I do to try to track down this discrepancy?