Closed imrooster closed 1 year ago
If you want to insert null data, try this:
$db->insert("table", [
"name" => "foo",
"email" => "foo@bar.com",
"phone" => $phone === "" ? null : $phone
]);
so the _PDO::NULL_EMPTYSTRING doesn't work??
Because the empty string ""
is still mapped as PDO::PARAM_STR
inside https://github.com/catfan/Medoo/blob/master/src/Medoo.php#L744
Of course, you can just create your insert() method to handle those values and then call Medoo's insert()
.
function myInsert($data) {
$result = [];
foreach ($data as $key => $value) {
$result[$key] = $value === "" ? null : $value
}
$database->insert("table", $result);
}
when i setup connection option as _PDO::ATTR_ORACLE_NULLS =>PDO::NULL_EMPTYSTRING
and run
$db->insert("table", [ "name" => "foo", "email" => "foo@bar.com", "phone" => "" ]);
the phone field still insert as empty string not null , WHY??