I am running a very basical query I expect to correctly fail, and it does as expected when ran through any MySQL client. But when run inside a PHP script with mysqli, it does a strange data conversion.
Query is next:
INSERT INTO gk_process_log (process_name, id_instance, date_start) select 'TestLog', NULL, '2020-10-19 14:29:11';");
Column id_instance is NOT NULL
so query should fail - full table definition is at bottom. As I said, it "properly" fails when ran through any MySQL client.
But when I run that query from inside a PHP script:
mysqli_query($this->getConnection(), "INSERT INTO gk_process_log (process_name, id_instance, date_start) select 'TestLog', NULL, '2020-10-19 14:29:11';");
it does insert a zero inside the NOT NULL column Query execution is plain as shown, there's no parameter binding involved.
Please anyone can explain why this happens and how can I workaround it?
Table definition:
CREATE TABLE gk_process_log (
id_process_log int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
process_name varchar(50) NOT NULL,
id_instance int(11) NOT NULL,
iteration_total INT NULL,
iteration VARCHAR(255) NULL,
iteration_step VARCHAR(255) NULL,
is_finished TINYINT(1) NULL,
date_start DATETIME NOT NULL,
date_iteration VARCHAR(255) NULL,
date_iteration_step VARCHAR(255) NULL,
date_end DATETIME NULL DEFAULT NULL,
state_data VARCHAR(255) NULL,
result_data VARCHAR(255) NULL,
UNIQUE INDEX instance (process_name, id_instance),
INDEX (process_name),
INDEX (id_instance),
INDEX (is_finished)
) ENGINE=InnoDB CHARSET=utf8