Do you use the same username/password for the other database as for vBulletin?
Then this is the problem:
The code in check_membership will use the current connection (for vBulletin) - but you close the connection, so it won't be available in vBulletin any longer after the call.
Try
PHP Code:
$SAIMClink = mysql_connect( "localhost", "myUsername", "myPassword", true );
This should create a new link, even if user/password are the same.
Another approach would be to use vBulletins DB-Class, and change the DB upon call end return.
Or use a different user/password.