Pregunta


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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top