skip to Main Content

I have 2 eccomerce sites that have almost identical product databases. I want to host the product tables in a separate database for the 2 eccommerce sites to share.

I tried connecting to 2 separate databases at once, but couldnt get it to work.

I use plesk and the only way to have multiple databases under the same user is to manually set it up on the server, but i cant figure it out.

My ideal database setup would be…

Site A:
shared_db (products)
db_A (orders, customers, etc...)

Site B:
shared_db (products)
db_B (orders, customers, etc...)

Whats the best way to go about this?

server: PHP 5.3, IIS7, PLESK, godaddy dedicated server.

2

Answers


  1. This all depends on whether the database connection you are using has access to the other database. If it does then you can simply refer to the other database (cross database join) in the following manner (the below query is for demonstrative purposes only, guessing at a schema):

    SELECT products.*, orders.*, customers.* FROM shared_db.products INNER JOIN db_B.orders on orders.product_id = products.id INNER JOIN db_B.customers on customers.id = orders.customer_id WHERE products.id = ?
    

    If your database connection does not have access to the other database, then you will have to issue two queries and combine them at the app layer.

    Login or Signup to reply.
  2. What database are you using?? If you are using MSSQL you may need to go into the primary database and enable cross database premissions. It is disabled by default. You may also need to define the fully quified name of the main database in the query of the the secondary database. If you need further clarification let me know.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search