Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
DB::update converting null to zero?
chrisv
January 2013
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
Harro
January 2013
Accepted Answer
I am not aware that is the case, what exactly does $values contain?
chrisv
January 2013
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
Harro
January 2013
The MySQL driver will convert false to 0, like it will convert 'string' to 0 (if the column is an int).
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
chrisv
January 2013
Harro
January 2013