2

I have two joomla site with different database.And I want to share all data one site to Another site .For example when I register A user in one website then it's updated on second site database also. I have this code for connect external database .But I am new In joomla so Do not know how to Implement this code.

<?php
$db = JFactory::getDbo();
?>

<?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 );
?> 
  • Do you want registrations and user profile updates to happen on both sites or only one? – Michael Yaeger Sep 21 '17 at 17:48
2

There is already a simple solution that exists to achieve your aims.

If you install the Fabrik extension you can then add a new database connection within the component admin settings. Using Fabrik you can then display and update fields and data from different databases within the same forms.

  • William Ellis@this is commercial extension – Sanjay Yadav Sep 21 '17 at 11:47
  • William Ellis@with this extension its possible to share two database on instant time? – Sanjay Yadav Sep 21 '17 at 11:52
  • William Ellis@query is when a user register in first site then it's data insert and update in both two database – Sanjay Yadav Sep 21 '17 at 11:57
  • The basic component is free. The databases are separate so in reality they couldn't be updated at the exact same time but very close to it! If you read the documentation then you can learn how to update the same field in separate databases. – William Ellis Sep 21 '17 at 12:00
  • William Ellis@@ I can understand .let me know it's possible to update different database at the same time . in joomla – Sanjay Yadav Sep 21 '17 at 12:04
1

EDIT 2:

I think this is not the explanation wanted for the user, but it's possible he needs to populate the information of his master website with a plugin system to the two databases.


If you are going to implement the code by using overrides and custom components, you just have to use, for example, this simple guide to obtain information from the other database:

https://docs.joomla.org/Selecting_data_using_JDatabase

EDIT:

More specifically, you have to create two objects, one for the local connection, and another one to the external connection.

$db = JFactory::getDbo();
$extDb = JDatabaseDriver::getInstance( $option );

And use the same query you create for the two objects:

$query = "UPDATE #__anytable SET column1 = value1";
$db->setQuery($query); $db->execute();
$extDb->setQuery($query); $extDb->execute();

PD: Don't post the credentials like user and password on the internet.

  • troyKoutei@ thanks for reply, but my query is how to connect two database.see this docs.joomla.org/Connecting_to_an_external_database – Sanjay Yadav Sep 21 '17 at 7:53
  • sanjay-yadav@ Put the external database in another object (in the code above you are overwriting the pointer of the local connection to the external). You only have to use the right object to select, update or delete in each object. For example: If you are going to update an object, use the same query on the two objects. – troyKoutei Sep 21 '17 at 8:01
  • troyKoutei@please read the question – Sanjay Yadav Sep 21 '17 at 8:35
  • troyKoutei@@I need to share database , I do not need any query, simply can you let me know How can I connect two database – Sanjay Yadav Sep 21 '17 at 8:37
  • sanjay-yadav@ In that case you have to make a plugin that updates each database with each of the cases you want to update the databases. I mean, you can't open two connections simultaneously in only one object (at least, i don't know if it's possible). – troyKoutei Sep 21 '17 at 8:41

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.