The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Connecting to a custom database using db_connect
Is there a sane way to access a custom database using vB's built in database classes?
The database is on the same local server as the vB one. Is there a recommended strategy on using db_connect and select_db? Like opening a second connection to the same server or just switching databases on the same connection? Is it even a sane idea to crowbar in a 2nd database that way? Over the years I created quite a few extra pages and stuff but so far I've been using completly "seperate" code to make them run. Since I'm in the process of migrating my 3.8 install to 4.2, though, I need to rewrite everything anyway and I'd love to, finally, create proper installable addons/plugins for everything. Yet, all the data is in the custom database, and I don't feel comfortable merging it with the forum tables. |
#2
|
||||
|
||||
You would be better off merging the 2 databases, and using table prefixes to keep them visually separated; however, if you are re-writing it for v4, then just take your time and write them properly using the same DB with whatever prefix VB is using,
Why are you not comfortable doing it this way? |
#3
|
|||
|
|||
Primarily because of backup reason.
Some of my apps, especially the largest one, don't necessarily need the vB environment and would do just as well as "standalones". Right now, when I want those tables backed up and/or transfered to a test server I just blindly mysqldump the whole secondary database. Same with restoring. After merging I'd need to specifically pick or exclude tables (forum takes about 500MB, 2nd db only 20-30MB). Knowing myself, this will end in confusion Would switching between databases cause any kind of trouble with the forum? Like ... my script switches to db2, forum script tries to access its own tables and ... *bam*? |
#4
|
||||
|
||||
No, it should work, but I'm not sure you will be able to use VB's db_query, you will probably have to make your own, for calls to your other DB.
|
#5
|
|||
|
|||
You could approach this situation in 2 different ways:
First way is to create an API for your apps which removes the need of database access inside of vBulletin. Second way is to initialize a new vB_Database class (refer to includes/class_core.php) with your app its database connection information. That way it should not interfere with vBulletin. |
#6
|
||||
|
||||
To use the existing vb structure to access the database just create a new instance of vbDatabaseMySQLi class and then call the connect method with the relevant information. See the file includes/class_core.php for details on what you need to do the above. After that you can use the standard db->query_read, db->query_write, etc. function calls.
|
Благодарность от: | ||
Dragonsys |
#7
|
|||
|
|||
Ok, so I did some experiments.
Using vB's existing connection and switching over to a custom database works ... kinda. The problem indeed is this Quote:
What works fine now, though, is including the database in the sql query itself. e.g. PHP Code:
So basically a prefix did the trick. And I get to keep both DBs seperate, too. Almost as good as eating cake |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|