Page 1 of 1

How do we get NULL into date columns w. prepared statements?

Posted: Sat Nov 13, 2010 9:36 pm
by Stokestack
Hi all.

I can't figure out how to get NULLs into MySQL date columns using prepared statements. Neither an empty string nor "NULL" result in a null entry in the DB; the columns wind up with 00-00-00 dates. There's no default value set on the column in the DB, nulls are allowed, and other rows (test data added with plain SQL statements) do contain nulls for the dates.

Any ideas? Thanks!

Re: How do we get NULL into date columns w. prepared stateme

Posted: Sat Nov 13, 2010 11:37 pm
by Weirdan
Stokestack wrote:Neither an empty string nor "NULL" result in a null entry in the DB; the columns wind up with 00-00-00 dates.
You need to bind real null:

Code: Select all

// ...
$date = null;
$stmt->bind_param('s', $date);

$stmt->execute();