lets say my table only has these members – id (key) and date (which defaults to NULL) .
Now when I want to insert a row with my php , do I need to check before my query whether date has a value or not or can I just insert like so –
$query = "INSERT INTO mytable VALUES(3,{$_GET['date]})"
And mysql would assign a NULL value to date ?
And does this hold true to a table no matter how large ?
e.g : can I insert many values that come from php and may be empty(or null) to a table , and mysql would automatically assign NULL to them (if I defined them as NULL by default of course) or do I need to do all kinds of checks before my inserts?
No, it will assign the value passed with the parameter
$_GET['date']. If the value is empty''and the date was of data typevarcharit will insert a value of''which is different thanNULLthen it will insert an empty. Thats becauseNULLand empty strings are not equal. They are two different things in SQL.If you want to insert
NULLvalues, either ignore this column in the insert columns list, then it will assigned with the default value which isNULL. Or write it explicitly in the values of theINSERTstatement.Note that: Your code this way is vulnerable to SQL injection. You should use prepared statements or PDO instead. See this for more details: