Insert or Update value in table mysql?
You can use db_merge() function. Here is the example.

db_merge('my_table')
  -&gt;insertFields(array(
    'name' =&gt; 'George',
    'last_name' =&gt; 'Niels',
  ))
  -&gt;updateFields(array(
    'last_name' =&gt; 'Niels',
  ))
  -&gt;key(array('name' =&gt; 'George'))
  -&gt;execute();


If there is no key ("name") with value "George", "name" and "last_name" values are inserted to the database table. If there is a record with key value "George", only the field "last_name" is updated with the specified value.