Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NULL to EMPTY_STRING #1082

Closed
imrooster opened this issue Apr 14, 2023 · 3 comments
Closed

NULL to EMPTY_STRING #1082

imrooster opened this issue Apr 14, 2023 · 3 comments

Comments

@imrooster
Copy link

when i setup connection option as PDO::ATTR_ORACLE_NULLS =>PDO::NULL_EMPTY_STRING

and run

$db->insert("table", [ "name" => "foo", "email" => "foo@bar.com", "phone" => "" ]);

the phone field still insert as empty string not null , WHY??

@catfan
Copy link
Owner

catfan commented Apr 14, 2023

If you want to insert null data, try this:

$db->insert("table", [
    "name" => "foo",
    "email" => "foo@bar.com",
    "phone" => $phone === "" ? null : $phone
]); 

@imrooster
Copy link
Author

so the PDO::NULL_EMPTY_STRING doesn't work??

@catfan
Copy link
Owner

catfan commented Apr 17, 2023

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);
}

@catfan catfan closed this as completed Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants