Created
June 13, 2015 00:40
-
-
Save Rady/d64410e2397665e947cb to your computer and use it in GitHub Desktop.
Joomla connecting to an external database and Query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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