In which cases work with more than one php database?

Asked

Viewed 54 times

1

I am working on a system where more than one company will have its space and I want to do something where companies register their products and visitors (users) can first of all see all companies and click on one of them see their products.

I thought of using a bank for each company, or just a tabala organizing the companies and with their code inserting the products to identify each company in their respective products.

What is the best way ? Someone who has been through this could give me a strength ?

Thanks in advance for your attention

1 answer

1


I believe that the best way is to work with tables, not a bank for each company.

Because a bank for each company, means different connections in the database to access data from each company, this over time can become confusing and complex the backups, bank maintenance, imagine you are updating a table of your system, and you have 3,000 registered companies, so that means 3,000 database, updating the tables of 3,000 database is really impracticable because you end up losing control of your system.

  • Thanks man, I needed this !

  • face can I ask a question ? So, because everything is treated as a single bank, there is danger of data exchange ? I think when I have several users registering from different companies. There is the possibility of a data exchange ?

  • 1

    Data exchange, you mean, given that an X company is registered in a Y company? If so, it depends solely on your bank modeling and how you will program, in which case it would be something like a BUG or failure, you have to program your system so that it can never happen. Do you have enough knowledge in a database? SQL, how to create a query, make a specific select, an Insert, etc? If you don’t strongly recommend studying this, before trying to model your system.

  • Yes I have this knowledge, thank you very much man ! Thanks a lot

  • In this case it would be interesting to work with more than one database, but the ideal is that it is a cluster with 2 Databases, a reading database and a writing database, where the writing DB data is replicated in the reading database, so you will have a better performance in both operations (Writing and Reading).

  • Regarding your question regarding the possible record of data exchanged by mistake, you need to model your database with at least two tables that relate to a cardinality 1 -> N for example, company table and product table, where in the company table a company would have a single record, and in the products table you use a foreign key referencing this company in each product belonging to it. If you are in doubt search google by cardinality modeling 1 to N. You should find more didactic examples of this data model scenario.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.