How to publish unpublished nodes programmatically
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);
}