Want to upgrade membership level using php

I know there is a function in the membershop plugin: current_user_on_level(2),
that will tell you if a user is on level 2.

But I am looking for a function that will move the current user to a different level.

For example, something like:

I am looking for a php script so I can move a user to a certain membership level, if he get a certain number of bonus credits.

Any Ideas?