• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Items and value from another db

Items and value from another db 9 years 9 months ago #31863

Hi,
I have 3 db in my localhost server (db1:joomla, db2:my stats, db3:other db).
Rsform working on db1.
Can I take results from db2?

The host is the same; user db and pwd db is the same.
Normally I write in the default value my code:
//<code>
$db =JFactory::getDBO();
....
...
return $ result;
//</code>


How can i do with another database in the same server?

Thanks!
The administrator has disabled public write access.

Items and value from another db 9 years 9 months ago #31864

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
Accessing tables that are in the same database as the Joomla! installation is done through this method:
$db = JFactory::getDbo();

However, if you are trying to connect to an external database, you will need a different approach. Basically, you will need to use
JDatabaseDriver->getInstance
as per this example:
 
// create an empty array to hold the options
$option = array(); 
 
// build the method's paramaters here:
 
$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 );
 

Straight from the Joomla! docs:

https://docs.joomla.org/Connecting_to_an_external_database

PS: this would require moderate scripting knowledge
My help is not official customer support. To receive your support, submit a ticket by clicking here
Last Edit: 9 years 9 months ago by cosmin.cristea.
The administrator has disabled public write access.

Items and value from another db 8 years 10 months ago #35339

I get a error on submission.
Can anybody help to find the solution.
Thanks.
$option = array(); //prevent problems
 
$option['driver']   = 'mysql';            // Database driver name
$option['host']     = 'localhost';    // Database host name
$option['user']     = 'user';       // User for database authentication
$option['password'] = '';   // Password for database authentication
$option['database'] = 'crm_db';      // Database name
$option['prefix']   = '';             // Database prefix (may be empty)
 
$db = JDatabaseDriver::getInstance( $option );
 
{
$db->setQuery('SELECT MAX acc_id FROM crm_accounts');
$nr_acc = $db->loadResult();
}
 
return $nr_acc;
$_POST['form']['nr_acc'] = $nr_acc;
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!