assigning a role to a user programatically
$uid = 123;// User ID of user that you want to add role to.
$role_name = 'Role to add'; // The name of the role to add.
if ($role = user_role_load_by_name($role_name)) {
  user_multiple_role_edit(array($uid), 'add_role', $role-&gt;rid);
}


Is how you should do it in Drupal 7. See https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_multiple_role_edit/7