I'm using zend-db in combination with zend-expressive. I have a handler which selects all records from a database table and returns the results as JSON response:
public function handle(ServerRequestInterface $request) : ResponseInterface {
$select = new Select();
$select->from('person');
$select->columns([
'id',
'name',
]);
$sql = new Sql($this->dbAdapter);
$statement = $sql->prepareStatementForSqlObject($select);
$result = $statement->execute();
$resultSet = new ResultSet();
$resultSet->initialize($result);
return new JsonResponse($resultSet->toArray());
}
What irritates me a little, that the response looks like this:
[{"id":"1","name":"tester"}]
The field "id" is of type INTEGER in my table (MySQL) and so I was expecting:
[{"id":1,"name":"tester"}]
Is there a way of an automatic type cast?