Skip to content

Instantly share code, notes, and snippets.

@Rady
Created June 13, 2015 00:40
Show Gist options
  • Select an option

  • Save Rady/d64410e2397665e947cb to your computer and use it in GitHub Desktop.

Select an option

Save Rady/d64410e2397665e947cb to your computer and use it in GitHub Desktop.
Joomla connecting to an external database and Query
function externalDatabaseQuery(){
$option = array(); //prevent problems
$option['driver'] = 'mysql'; // Database driver name
$option['host'] = 'db.yourhost.com'; // Database host name
$option['user'] = 'root'; // User for database authentication
$option['password'] = 'your-password'; // Password for database authentication
$option['database'] = 'database-name'; // Database name
$option['prefix'] = 'abc_'; // Database prefix (may be empty)
$db = JDatabaseDriver::getInstance( $option );
$query = "SELECT * FROM YourTableName WHERE 1=1 ORDER BY ID"; // SQL HERE
$db->setQuery ( $query );
$rows = $db->loadObjectList ();
foreach ($rows as $row) {
echo $row->ID; // others code here.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment