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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Stokestack
Forum Newbie
Posts: 14
Joined: Thu Sep 16, 2010 2:37 am

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

Post 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!
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

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

Post 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();
Post Reply