In Drupal 7, I'm being sent an array of values from a user submission that are being mapped directly to a database table.
Some of those are blank and I'd like to set those fields to SQL-style NULL
in the database.
To do this, my values array has the empty or blank fields set to PHP's NULL
:
array('field1' => 'value1', 'field2' => NULL)
And I'm using db_update()
like this:
$result = db_update('table_name')
->fields($record)
->condition('cmid', $form_state['values']['cmid'])
->execute();
However, db_update()
doesn't appear to like NULL
values in the $record
array. I'm not seeing any sort of errors, unfortunately, except that no updates are being made to the database and that $result
is returning a falsy value.
How should I be using db_insert()
or db_update()
if some my values may be blank at times, and I'd like these to equate to setting those respective database fields to NULL
?