Getting boolean values with Doctrine DBAL in Symfony
I am using DBAL in a Symfony project to access data in a Mysql database. When querying tables with boolean fields (created as tinyint), I get tinyint values in PHP, but I would like to get booleans.
Somehow, I would like to get the same mapping as directly using Doctrine.
I thought the mapping conversion (from mysql to php) was already implemented in DBAL, but I'm not sure if it would supposedly work that way (this layer maps the values back).
I tried to register a custom mapping similar to the following but with no success:
$this->conn->getDatabasePlatform()->registerDoctrineTypeMapping('tinyint', 'boolean');
$sql = "
SELECT se.survey_id, se.anonymous
FROM survey_edition se
";
$stmt = $this->conn->prepare($sql);
$stmt->execute();
$result = $stmt->fetch();
In this case, "anonymous" is a tinyint (1) field in Mysql, but I would like $ result ['anonymous'] to be a boolean, not an integer.
Do you know if it is possible to get boolean values in PHP from a Mysql query via Doctrine DBAL?
Thank.
source to share