See the WP_User class, you can use this to add and remove roles for a user.
EDIT: I really should have provided more information with this answer initially, so i’m adding more information below.
More specifically, a user’s role can be set by creating an instance of the WP_user class, and calling the add_role()
or remove_role()
methods.
Example
Change a subscribers role to editor
// NOTE: Of course change 3 to the appropriate user ID
$u = new WP_User( 3 );
// Remove role
$u->remove_role( 'subscriber' );
// Add role
$u->add_role( 'editor' );
Hopefully that’s more helpful than my initial response, which wasn’t necessarily as helpful.