drupal_write_record
updates an entire record, not a single column. With drupal_write_record
you could do this.
$node = node_load($nid);
$node->vid = $vid;
drupal_write_record('node', $node, 'nid');
But dealing with nodes, you can use node_save
instead, which also handles saving fields and other data. Using node_save
is recommended way of saving alterations to a node, since it also deals with revisions issues along with fields, hook notification ect. It's simple to use:
$node = node_load($nid);
$node->vid = $vid;
node_save($node);
If you want to update a single value in a datebase, you can use SQL (db_query
) or the db_update
function which is two ways of running SQL on your database. The db_update
utilizes the Drupal query builder, and will work on any database backend the Drupal supports (now and in the furture):
db_query("UPDATE {node} SET vid = :vid WHERE nid = :nid;",
array(':nid' => $nid, ':vid' => $vid)
);
$num_updated = db_update('node')
->fields(array(
'vid' => $vid,
))
->condition('nid $nid)
->execute();
drupal_write_record
will itself use db_update
, a snippet of the code looks like this:
$query = db_update($table)->fields($fields);
foreach ($primary_keys as $key) {
$query->condition($key, $object->$key);
}
Which basicly creates an update query, updating all of the fields, and using all of the values set in primary key as the condition.