Skip to content

In MySQL strict mode PHP boolean values produce error #32

Open
@GoogleCodeExporter

Description

@GoogleCodeExporter
When you have a MySQL database connection set to STRICT_TRANS_TABLE, the 
database server won't accept the PHP true/false value, it refuses it with the 
following error: "SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 
'' for column 'xy' at row 1".

The error originates from that PHP tries to pass the boolean value as a 
PHP-boolean, but in MySQL such value doesn't exist. So it's necessary to simple 
cast it to integer.

In the mapper's toArray() function (~56. line) I replaced the following:
'<?=$column['field']?>' => $model->get<?=$column['capital']?>(),

to:

<?php $typeCast = $column['phptype'] == 'boolean' ? ' (int)' : '';?>
'<?=$column['field']?>' =><?=$typeCast?> $model->get<?=$column['capital']?>(),

This patch works fine, but it doesn't handle other DB engines or when you need 
boolean values in PHP code (aka. you need the toArray() function not for save 
into the database).

Original issue reported on code.google.com by [email protected] on 20 Aug 2012 at 10:33

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions