I want to create a script that counts threads words’ count in a vBulletin forum. Bascially, I want to pull that database from the mysql database, and play with it. I don’t have experience working with vBulettin, so I’m thinking of two ways:
-
Does vBulletin provides API to handle database stuff. (Allow me to grab all the threads content, and URLs). I’m almost sure there is, a link where to start?
-
Is there a solution doing this without the interferance of vBulletin. This means grab the data manually from the mysql database and do stuff the typical way.
I’ll prefer the second method if the vBulettin learning curve is too steep. Thanks for the advice.
Is this for vBulletin 3 or 4?
I mostly work with vB3, and the quickest way to include all of the vBulletin resources is to create a new php file in your forums directory with the following code.
That $vbulletin variable is the registry object that contains just about everything you’re ever going to need, including the database connection and it’s read and write functions, userinfo data, cleaned _POST and _REQUEST values, and a lot more (phrases, session data, caches, etc).
There are 4 database functions you’ll use the most.
query_read is what you would use when you expect more than one result that you intend to loop through. For example, if you wanted to count all the words in a single thread, you would would need to query the post table with the threadid, loop through each post in that thread and count all the words in the message.
Note: “TABLE_PREFIX” is a constant set in config.php. It’s important to always prepend the table name with that constant in case other forums decide to prefix their tables.
The query_first function is what you would use when you need to fetch a single row from the database. No looping required or anything like that. If, for instances, you wanted to fetch a single user’s information from the database – which you don’t need a query for, but we’ll do it as an example – you would use something like this.
Lastly, if you wanted to update something in the database, you would use “query_write“. This function is pretty straight forward. This function just takes any MySQL update insert or delete query. For example, if I needed to update a user’s yahoo id, you would do.
Hopefully this will help you get started. I would recommend using vBulletin 3 for a little while until you’re comfortable with it. I think it’ll be easier on you. Most of this will translate to vBulletin 4 with some tweaking, but that code base is not as friendly to new comers.