|
|
|
|
|
|
|
|
|
Re: Error with date field [message #7812 is a reply to message #7804] |
Thu, 23 March 2023 10:51   |
htManager
Messages: 452 Registered: May 2014
|
Senior Member |
|
|
I created a new table with the following specifications:
$fieldspec['id'] = array('type' => 'integer', 'type_native' => 'int','size' => 10, 'minvalue' => -2147483648, 'maxvalue' => 2147483647, 'pkey' => 'y', 'required' => 'y');
$fieldspec['test_datum'] = array('type' => 'date', 'size' => 12);
// primary key details
$this->primary_key = array('id');
When I insert a new record with my application, the line 1.631 in dml.mysqli.class.inc: $result = mysqli_query($this->dbconnect, $this->query); is responsible for inserting the record in my database with the right id and the value 0000-00-00 in the field 'test_datum', if I leave this empty in my screen. I examined the database table before and after executing this line. Before, the record wasn't visible/inserted, afterwards it was.
These variables shows my debugger before executing the line:
$this->query = INSERT INTO test_datum SET `id`='2', `test_datum`=''
client_info = mysqlnd 8.2.0
server_info = 10.4.27-MariaDB
Where else can I search for the problem? My debugger doesn't show any further information. I only can see the inserted record in the database table.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Error with date field [message #7830 is a reply to message #7829] |
Tue, 04 April 2023 04:44   |
AJM
Messages: 2378 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
If a date field is only valid when certain conditions are met then it should be nullable (not defined with NOT NULL). I am using MySQL version 8.0.32 with SQL_MODE set to
ANSI_QUOTES,STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_ENGINE_SUBSTITUTION and this prevents me from setting a date field to '' instead of NULL.
As I said in an earlier post, if you do not have NO_ZERO_IN_DATE,NO_ZERO_DATE set then inserting an invalid date (such as an empty string) MySQL will instead replace it with '0000-00-00'.
|
|
|
|