Update query in Drupal 7 (db_update)

Public

Update query in Drupal 7

</> CopyGet raw version
php
  1. // Old code.
  2. db_query("UPDATE {profile_field} SET weight = %d, category = '%s' WHERE fid = %d", $weight, $category, $fid);
  3.  
  4. // DBTNG.
  5. // More info at https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_update/7
  6. db_update('profile_field')
  7. ->fields(array(
  8. 'weight' => $weight,
  9. 'category' => $category,
  10. ))
  11. ->condition('fid', $fid)
  12. ->execute();

Comments

dhramendra's picture

Very helpfull post for me.