Skip to content

Instantly share code, notes, and snippets.

@victor-shelepen
Created September 6, 2016 08:43
Show Gist options
  • Save victor-shelepen/da9f888b573dba195bc9b60dacbee3a3 to your computer and use it in GitHub Desktop.
Save victor-shelepen/da9f888b573dba195bc9b60dacbee3a3 to your computer and use it in GitHub Desktop.
Example how to use db_update, db_select. Case: Update comment possibility including revisions.
<?php
db_update('node') // Table name no longer needs {}
->fields(array(
'comment' => 1,
))
->condition('type', 'feature')
->execute();
$subquery = db_select('node')
->addField('node', 'nid')
->condition('node.type', 'feature', '=');
db_update('node_revision')
->fields(array('comment' => '2',))
->condition ('node_revision.nid', $subquery, 'IN')
->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment