Skip to content
Advertisement

Using PHP/PDO to set a NULL as value when UPDATE by array

i am executing SQL statement like this with PDO.

and $_POSTData_array is like this

the problem is i can’t get the null as null in db, its update as blank. any help???

UPDATE !

as per comment by Álvaro González i tried var_dump().

var_dump() is much better. I need to insist: how do you know that you’re getting NULL values upon insertion? – Álvaro González

so actually there was no NULL set in the $_POSTData_array. guess var_dump() way much more batter then print_r() to verifying data.

Advertisement

Answer

Found a Solution.

Solution 1 while creating the array elements use array_push.

Solution 2 using array_map to set Null to blank elements after creating the array before executing PDO statement.

new result of var_dump($_POSTData_array); for both solutions

Thanks for all the help everyone.

and to those who ‘downvote‘ my question, guess what! there is a solution after all.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement