Take a read through the following to get a sense of how it works, and then find the hooks in the vB code to see what is available to you for use in your plugins:
That is, if you want to run a query in a plugin located at hook X, you need to know what is available, what to use, and what to avoid:
Code:
// Example...
$db
$vbulletin->db
$this->dbobject
$this->registry->db