Im currently using CodeIgniters active record class to UPDATE a MySQL table. One of the columns is an INT who’s default value I’ve set to NULL and set the NULL field to TRUE. When I INSERT a record and leave that particular field blank in the form, no problem, it’s set to NULL. However, when I do an UPDATE with the field blank in the form, MySQL sets the value to 0. Is there a way to have MySQL intepret an UPDATE the same way an INSERT is done i.e. if the form value is blank it sets it to NULL and not 0?
Cheers
Most likely empty string ” is sent to the database thus it is cast to INT field as 0 – check exact SQL query (eg. by enabling profiler: $this->output->enable_profiler(TRUE) in your controller). If that’s the case add a snippet to your model that will replace ” with NULL while updating.