I’m working on Codeigniter3 project where i have several database tables with specified date field.
Date field is marked null and default value is null too.
When I insert new record to a table I simply avoid “touching” this field so entry NULL is added to a date field automatically by mysql.
But, when this date field contains some date (not null), and from some reason user wants to delete this entry and set this field back to null mysql enters 0000-00-00 instead of NULL.
Anyone had similar problem and did it found solution?
I have tried several solutions like:
$data = array (‘fld_date_from’ => NULL,); (in my controller – tried with quotes, “false” option too – not working),
tried with SET field to null command in model – not working
Tried also some other solutions I have found on StackOverflow and in CI3 domumentation.
Each one after update of field is entering 0000-00-00, neither one NULL.
One solution might be to use the following query to set the SQL mode for your database table:
SET sql_mode = 'NO_ZERO_DATE';
See this related question or the Server SQL Modes guide for further details.