CMS: connect with external database in joomla

CMS

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";
$db->setQuery($query);
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 🙂

More resources like CMS
GET
100%

satisfaction
or
Get Your Money
Back

Just for you

pdf_icon_case

Download our WP checklist below and review your Wordpress site's performance today for free

DOWNLOAD

interested?

Let's Discuss Now