Doctrine 2 DBAL returns only string datatypes
-
15-07-2021 - |
Question
I'm building a simple REST backend using Silex micro-framework.
Inside each controller, I'm running some query against MySQL database (using Doctrine 2 DBAL API), like the follow:
$app->get('/customers', function (Application $app) {
$recordset = $app['db']->fetchAll('SELECT id, name FROM Customers');
return $app->json($recordset);
});
Can anybody explain to me why Doctrine DBAL returns only string
datatype, regardless column definitions? Below is the corresponding output using PHP var_dump($recordset)
function (note that id
field should be of type integer, not string):
array(1) {
[0]=>
array(2) {
["id"]=>
string(5) "10043"
["name"]=>
string(20) "Hey, I'm just a test"
}
}
Thanks for your help.
Solution
As suggested by Maerlyn, this seems to be a known issue of PDO driver and, therefore, of Doctrine DBAL.
Without making use of the mapping abilities provided by Doctrine 2 ORM layer, I've found this answer as a possible workaround to DBAL limitations.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow