To continue on the $db versus $vbulletin->db:
The object that is used is $vbulletin->db.
To save on the keyboards of the developers

$db is defined as a reference to the addresspace of $vbuylletin->db in the top-level scope.
This means that you can exchange $db and $vbulletin->db if you want, they both point to the same object.
If you however go into a function for example, then it will probably not have $db in it's scope. You will find also stock vB files where not $db is used but $vbulletin->db because $db is not in the scope.
To avoid confusion and scope problems, i personally also always code the full qualification to the object, ie. $vbulletin->db. Like that is is maybe a bit more typing, but i can always use that, and it is more "correct" on an object oriented environment.
You might find some guidelines over here:
https://vborg.vbsupport.ru/showpost....72&postcount=5
(With thanks to DAnny for finding the post for me)