Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In MySQL strict mode PHP boolean values produce error #32

Open
GoogleCodeExporter opened this issue Oct 13, 2015 · 0 comments
Open

In MySQL strict mode PHP boolean values produce error #32

GoogleCodeExporter opened this issue Oct 13, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant