I've this column in MySql:
male BOOLEAN COMMENT "true for male",
I'm using this query to insert using PDO wrapper in Drupal:
$id = db_insert('Person')->fields(array(
.......
'male' => false,
)
)->execute();
I'm getting this error:
WD php: PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect ^[[31;40m^[[1m[error]^[[0m integer value: '' for column 'male' at row 1: INSERT INTO .....
But if I replace with 'male'=>true
, the query works. Surprisingly if I replace 0
or (int)false
with false
then also it works!
It means false is getting converted to '' ( empty string) in this context.
I'd like to know why it's getting converted to a string here.
I've got related question here: In PHP why is true cast 1 and false cast an empty string? but it does not answer why PHP is casting false to string?