I'm 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'd like to get the same mapping as using Doctrine directly.
I thought that the mapping conversion (from mysql to php) was already implemented in DBAL, but I'm not sure if it's suppose to work this way (this layer mapping values back).
I have tried registering a custom mapping like the following one, but 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 that $result['anonymous'] to be a boolean instead of an integer.
Do you know if it is possible to get boolean values in PHP from a Mysql query through Doctrine's DBAL?
Thanks.
Without using some ORM
you cannot (as far as I know it) define model types.
Way to resolve this would be to iterate over the data and cast boolean values such as:
$item[$i]['foobar'] = (bool)$item[$i]['foobar']
But this is not even close to ideal solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With