tags:

views:

235

answers:

3

I need to connect to another database in Joomla! that's on another server. This is for a plugin and I need to pull some data from a table.

Now what I don't want is to use this database to run Joomla!, I already have Joomla! installed and running on its own database on its server but I want to connect to another database (ON TOP of the current one) to pull some data, then disconnect from that 3rd party database - all while keeping the original Joomla database connection in tact.

A: 

Can you create a generic mysql-php conection inside your plugin code to create a connection ? like

mysql_connect("remot_server_ip:3306","user","pass"); mysql_select_db("your database"); //code goes here : : :
mysql_close(connection);

rwik
A: 

Hello, You can connect to an external database from your joomla instance without using the current ressource of your joomla DB. Try this:

<?php
$option = array(); //prevent problems

$option['driver']   = 'mysql';            
$option['host']     = 'dbase.host.com';    
$option['user']     = 'login';       
$option['password'] = 'pwd';   
$option['database'] = 'anotherdb';      


$db = & JDatabase::getInstance( $option );
?>
Fayez
A: 

Hi,

I had same problem before. Fond a good tutorial showing how to connect to multiple database and switch back and forth, it also has sample code. It explains how to connect to multiple (internal and external) databases factory style, without creating multiple connections per request. This means that if you create database instance in controller same connection will be used in the model. Improves performance.

Another good explanation is on Joomla Documentation site [http://docs.joomla.org/How_to_connect_to_an_external_database].

Alex