add role on WordPress in PHP on a second database

I managed to solve after several attempts using the following code:

// Insert the role
$role = array('gold_role' => 1);
$serialized_role = serialize($role);
$DB_MEMBERSHIP->insert('wpvm_usermeta', array('user_id' => $user_id, 'meta_key' => 'wpvm_capabilities', 'meta_value' => $serialized_role));

It works very well and doesn’t slow down the shopping experience.