i've removed the username and password of your db connection.
be careful not to post such informations when asking for help
as for your question, normally that's because you are calling the db within a function without globalizing that object.
try to add a global $vbulletin; before the errorproducing line.
also try to use better formating of your code, codingstandarts help when it comes to find bugs