If you require() global.php, it basically "loads vBulletin". This gives you access to the database, user sessions, everything. Depending on what you are doing, you may or may not want this.
Anyway, whenever you see the database object ($db, $this->db, $vbulletin->db etc), it is going through vBulletin instead of just through MySQL.
PHP Code:
function comparestart($today, $users)
{
global $vbulletin;
foreach ($users as $user)
{
// Just to keep things clear
$userid = $user[0];
if ($today == $user[1])
{
promote($userid);
}
}
}
function promote($userid)
{
global $vbulletin;
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET usergroupid = 9
WHERE userid = $userid ");
echo "User $userid promoted!<br />";
}
Not much new here... the global keyword gives $vbulletin global scope, I assume you know what that means because you are passing everything into the functions properly. You could also pass it (by reference! we don't want to duplicate it) into the functions if you prefer that method.
My query is essentially the same, too. I added the constant TABLE_PREFIX before the table name, which is pretty much the standard now so it will work no matter what your prefix is (or isn't). There is no need to put 9 in quotes, as it is an integer. Unless you have a list of userids, you can simply check if left side = right side.