Connect to an external database from a Joomla extension
Hello guys, sometimes we may need to connect to an external database from a custom made joomla extension. It is possible to connect to an external database with the help of JDatabase class. The following sample function connects to an external database and execute a query in the database and returns the result
function getDetails()
{
$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";
$db->setQuery($query);
return $db->loadAssocList();
}