Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>MySQL <em>does</em> allow <code>NULL</code> values for <code>datetime</code> fields. I just tested it:</p> <pre><code>mysql&gt; create table datetimetest (testcolumn datetime null default null); Query OK, 0 rows affected (0.10 sec) mysql&gt; insert into datetimetest (testcolumn) values (null); Query OK, 1 row affected (0.00 sec) mysql&gt; select * from datetimetest; +------------+ | testcolumn | +------------+ | NULL | +------------+ 1 row in set (0.00 sec) </code></pre> <p>I'm using this version:</p> <pre><code>mysql&gt; select version(); +-----------+ | version() | +-----------+ | 5.0.45 | +-----------+ 1 row in set (0.03 sec) </code></pre> <p>EDIT #1: I see in your edit that the error message you are getting in PHP indicates that you are passing an empty string (i.e. <code>''</code>), not <code>null</code>. An empty string is different than <code>null</code> and is not a valid <code>datetime</code> value which is why you are getting that error message. You must pass the special sql keyword <code>null</code> if that's what you mean. Also, don't put any quotes around the word <code>null</code>. See my <code>insert</code> statement above for an example of how to insert <code>null</code>.</p> <p>EDIT #2: Are you using PDO? If so, when you bind your null param, make sure to use the <code>[PDO::PARAM_NULL][1]</code> type when binding a <code>null</code>. See the <a href="https://stackoverflow.com/questions/1391777/how-do-i-insert-null-values-using-pdo/1391796#1391796">answer to this stackoverflow question</a> on how to properly insert <code>null</code> using PDO.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload