Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
DB::update converting null to zero?
  • It appears that DB::update is converting my null value to a zero when I execute the update.

    The code is: 
        \DB::update('MyTable')->set($values)->where('MyTableId', $id)->execute();

    I have an INT(10) field in the table which allows nulls, but when I pass a null in $values, the field gets set to 0.

    Would DB::update be doing this? If so, is there any way I can stop it doing this?

    I'm using FuelPHP 1.4, PDO driver to MySQL database.

    Thanks, Chris
  • HarroHarro
    Accepted Answer
    I am not aware that is the case, what exactly does $values contain?
  • Mea culpa! 

    I'm not quite sure how it happened, but I was passing false instead of null. It seems the query builder converts false to '0' for INT fields.

    That will teach me to test by using if ($val == null) instead of if ($val === null)!

    Thanks for your prompt response, as always,

    Chris
  • The MySQL driver will convert false to 0, like it will convert 'string' to 0 (if the column is an int).

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion