In my insert method of my database class I pass the parameters as an array:
$sql='INSERT INTO `'.$table.'` (`'.implode('`, `',array_keys($params)).'`) VALUES ("' . implode('", "', $params) . '")';
As you can see, the array gets imploded.
My $params for example looks like this:
$params = [
'field1' => 'sometext1',
'field2' => 'sometext2',
'stamp_created' => NULL
]
My field 'stamp_created' must be set NULL, so that the date of creation gets displayed in the data row in the database. However, imploding the array turns NULL to an empty string "":
VALUES ('sometext1', 'sometext2', '')
How do I achieve that NULL does not get ignored in my implode operation? My desired result is:
VALUES ('sometext1', 'sometext2', NULL)