I have a form, that has some optional inputs, that the user can skip from updating, those inputs can be empty, the issue is when I update a column that is set to NULL, the query will update that column to a blank "" instead of keeping it as null.
My concern is how efficient is this on MySQL specially large tables, is there a difference in performance when values are set to Blank VS NULL. If yes then I will make sure all empty inputs are updated as NULL.
This is the code am using to avoid blank, is there a better way to it?
#Avoid blank with NULL
$value1 = !empty($_POST['input1']) ? $_POST['input1'] : NULL;
$value2 = !empty($_POST['input2']) ? $_POST['input2'] : NULL;
NULLis the absence of a value. They are different semantically.NULLis forUNIQUE INDEX: if you create one on multiple value and one of those value areNULL, the index won't workprepare, then it still ends up going in as a blank, and not a null. You would have to do a condition on the placement of?vsNULLin the actualpreparesql string. And then dynamically include the proper number of bound variables off that initial setup. A messy thing to do.if (is_null($start) || $start=='' || $start=='0000-00-00 00:00:00') {...}. I bet the server harly cares but it really hurts my efficiency ;-)