0

In using the MySQL Database, here is the default query in populating lists:

$db = JFactory::getDbo(); 
$query = $db->getQuery(true); 
$query->select(array('name', 'email', 'username')) 
   ->from($db->quoteName('#__my_users')) 
   ->where($db->quoteName('user_id').'=42'); 
$db->setQuery($query); 
$row = $db->loadRow(); 

How can I configure which database I want to use? I need to get data from a different database which in my case, Oracle.

4

There is a file called configuration.php in root directory. Open that file, find:-

public $dbtype = 'mysqli';

change that value to:

 public $dbtype = 'oracle';

this will change database driver, list of drivers files can be found in:-

libraries/joomla/database/driver folder,

For more info see this article. Hope this helps.

Update - If you want to use only in some section then, instead of getting instance of database like

$db = JFactory::getDbo();

try :-

$db = JDatabaseDriver::getInstance($options);

where

$options = array('driver' => 'driver_name', 'host' => 'host', 'user' => 'user', 'password' => 'password', 'database' => 'db_name', 'prefix' => 'prefix');
  • thanks for your answer. However I don't plan to use Oracle in my whole application, just within a form. – Break the Law Jan 30 '15 at 7:25
  • 2
    For that you can get instance of JDatabaseDriver, you can pass array of options here, with which driver you can use. For that please take a look at JDatabaseDriver class. [not tried though] – subashbasnet8 Jan 30 '15 at 7:30
  • do you know what is the driver used in oracle? i tried using 'driver' => 'oracle' but results with an error: Could not connect to PDO: could not find driver – Break the Law Jan 30 '15 at 9:19
  • I have just tried to get instance of database, where JDatabaseDriverOracle Object is created. could you please show your tried code? – subashbasnet8 Jan 30 '15 at 9:22
  • please take a look at my update – Break the Law Feb 3 '15 at 1:04
1

Joomla Docs is a nice documentation site ;-)

Connecting to an external database https://docs.joomla.org/How_to_connect_to_an_external_database

<?php
$option = array(); //prevent problems

$option['driver']   = 'mysql';            // Database driver name
$option['host']     = 'db.myhost.com';    // Database host name
$option['user']     = 'fredbloggs';       // User for database authentication
$option['password'] = 's9(39s£h[%dkFd';   // Password for database authentication
$option['database'] = 'bigdatabase';      // Database name
$option['prefix']   = 'abc_';             // Database prefix (may be empty)

$db = JDatabaseDriver::getInstance( $option );
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.