Friday, May 13, 2016

db_merge combination of db_insert and db_update

In drupal 7, there is a something new for table insertion and update. That is called db_merge which combines db_insert and db_update in a single query for single or multiple row insert and update.

$query = db_merge('table_name')
                    'field1' => value1,
                    'field2' => value2,
                    'field3' => value3,
                    'field3' => value3,
                ->key(array('field2' => value2))

No comments:

Post a Comment