Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Save products to multiple databases


radu34

Recommended Posts

I have multiple different oscommerce stores, but one of them is the main store with the main database.

The rest are using different databases (but the same content) and i want to do the following:

 

When adding a product or a category in the main store, the same product/category to be added in the others.

 

I added an $_databases configuration array in the admin/includes/configure.php, like this:

 

$_databases = array (

array(

'DB_SERVER' => "localhost",

'DB_DATABASE' => "osc1",

'DB_SERVER_USERNAME' => "user1",

'DB_SERVER_PASSWORD' => "pass1",

),

array(

'DB_SERVER' => "localhost",

'DB_DATABASE' => "osc2",

'DB_SERVER_USERNAME' => "user2",

'DB_SERVER_PASSWORD' => "pass2",

),

array(

...

),

);

 

and then in categories.php, after

if ($action == 'insert_product') {

and after

$sql_data_array = array_merge($sql_data_array, $insert_sql_data);

, before adding the product in the DB, i do a foreach on $_databases, and for each db configuration array,

i open a new mysql link and add the product; after that i close the link and the insert the product in the main db.

 

I do something like this:

foreach ($_databases as $db) {

tep_db_connect($db['DB_SERVER'], $db['DB_SERVER_USERNAME'], $db['DB_SERVER_PASSWORD'], $db['DB_DATABASE']);

// do the processing

tep_db_close();

}

I tried it using persistent connections also, because all the connections had the same mysql_link code.

I tried using different names for connections with the $link param:

tep_db_connect($db['DB_SERVER'], $db['DB_SERVER_USERNAME'], $db['DB_SERVER_PASSWORD'], $db['DB_DATABASE'], 'other_link');

and at the end, tep_db_close('other_link');

 

It doesn't work at all.

It either inserts in the main db only, or it inserts in one of the secondary databases only, but not in all.

 

I know this isn't the best way i could do it, because it implies processing of the parent categories also, which i partially handle at this point, but the problem is that i cannot make the product be inserted in all databases.

 

Any idea would be appreciated.

Thanks in advance!

Link to comment
Share on other sites

what about orders, settings for every store? are they stored in the same main database?

Please read this line: Do you want to find all the answers to your questions? click here. As for contribution database it's located here!

8 people out of 10 don't bother to read installation manuals. I can recommend: if you can't read the installation manual, don't bother to install any contribution yourself.

Before installing contribution or editing/updating/deleting any files, do the full backup, it will save to you & everyone here on the forum time to fix your issues.

Any issues with oscommerce, I am here to help you.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...