views:

163

answers:

2
A: 

You can't make generic code, as the what Drupal use is the role id (rid) of a role, which is a serial.

A users roles, is in the user_roles table containing uid and rid, so to remove a role you would do:

global $user;
$rid = x; // x = the id of the role to remove
db_query("DELETE FROM {user_roles} WHERE uid = %d AND rid = %d", $user->uid, $rid);

To give the new role you could do:

$record = array(
  'uid' => $user->uid,
  'rid' => y, // y = the id of the role to give.
);
drupal_write_record('user_roles', $record);
googletorp
A: 

thanks this worked! 1 note however the table is called users_roles...plural!

Marques

related questions