PDA

View Full Version : Connecting to new database inside admincp


BamaStangGuy
11-13-2007, 01:05 AM
I have another database that I want to pull info from and show the stats on the vbulletin admincp when I login. What's the best way to connect to another database to do such things?

Analogpoint
11-13-2007, 03:27 AM
mysql_connect (http://www.php.net/manual/en/function.mysql-connect.php)
mysql_select_db (http://www.php.net/manual/en/function.mysql-select-db.php)
mysql_query (http://www.php.net/manual/en/function.mysql-query.php)

Not necessarily the best way, but probably the simplest.

BamaStangGuy
11-13-2007, 05:02 AM
k, that was what I was planning on doing I just wanted to see if others had different methods.

Thanks.

Eikinskjaldi
11-14-2007, 02:47 AM
Assuming its a database on the same server as the main vb one, you just need to add a database prefix to the sql. Mysql doesn't really care where tables live, and is even more than happy to join across databases.

select db1.table1.fieldA, db2.table2.fieldB
from db1.table1
join db2.table2 using (fieldC)

You can use the vb db wrapper for this ($vbulletin->db->query etc)

Analogpoint
11-14-2007, 01:00 PM
Assuming its a database on the same server as the main vb one, you just need to add a database prefix to the sql. Mysql doesn't really care where tables live, and is even more than happy to join across databases.


select db1.table1.fieldA, db2.table2.fieldB
from db1.table1
join db2.table2 using (fieldC)


You can use the vb db wrapper for this ($vbulletin->db->query etc)

Assuming your vBulletin MySQL user has permission to access the other database, that's fine