How to publish unpublished nodes programmatically I have some unpublished nodes, for which I have their node IDs. How can I programmatically publish them?
Is it correct to achieve it in custom module using a query like the following?

db_query("UPDATE {node} SET status = 1 WHERE nid = %d", $nid)
Using db_query() is a Drupal 6 method, which is not used in Drupal 7. 
To achieve your job I suggest this code (without any manual query).

// load the node object
$node = node_load($nid);
// set status property to 1
$node-&gt;status = 1;
// re-save the node
node_save($node);


If you have more node ID, and you want to publish all those nodes, you can use the following code.

$nids = array();
// Load all nodes in one go for better performance.
$nodes = node_load_multiple($nids);
foreach ($nodes as $node) {
  // set status property to 1
  $node-&gt;status = 1;
  // re-save the node
  node_save($node);
}