connect with external database in joomla

Hello everybody,

Sometime we may need to use any external database within our existing Joomla setup. Off course we can do it by using core PHP code. But this is not a good way to follow. So we can connect with external database using below code.

$options = array();
$options['driver'] = 'mysql';
$options['host'] = 'localhost';
$options['user'] = 'dbuser';
$options['password'] = 'dbpassword';
$options['database'] = 'databasename';
$options['prefix'] = 'tblprefix_';
$db = & JDatabase::getInstance($options);
$query = "SELECT * FROM #__example_table";
return $db->loadAssocList();

We should put all database connection related information in array variable $options. Then use getInstance() function from Jdatabse. Now you can use Joomla’s default database operation.

Hope it helps ….

Keep it up..
Coreway Solution 🙂