multiple similar applications in a single database - php

i'm using codeigniter.
i'm limited to 1 mysql database.
if i have a web application with many tables for use on 1 company.
i would access it like:
http://www.abc.com/login
http://www.abc.com/member/sales.php
if i want to use the same application for other companies in the same database, how should i proceed? and how can i access it using codeigniter?
i can't seems to figure it out.
many thanks for your guidance.

Try to create a table names with the prefix of the Company name that will give the clarity of the table names also...In the code u can easily identify the Name with the prefix.

I guess in your case codeignitor is mere a development framework not more than that so try to create a seperate table with name of companies and use PID of company table for identify all the records related to the company.
Or if creating schemas is not an issue than codeignitor provides you facility to connect more than one database at a time, please go through following link -
"Connecting to Multiple Databases"

Related

How do I allow multiple users to use my web app & database?

I am a novice in SQL organization! I essentially have an inventory app written in php with an sql database. If I want to allow multiple users to create inventories independent of one another using my web app, would I just use foreign keys linked to a user table or should I be creating new tables for each user, or another option that I have not considered?
thank you!
I have said before that it's a code smell if you hear the word "per" in the context of of database design.
I'm going to create a table per user.
That could result in a lot of tables. How many users will you have? Hundreds? Thousands? Millions? Can your database handle millions of tables? How can you test this? Does that mean your application must create new tables on the fly as new users register?
In your application code, would you create a separate PHP class for each user? Probably not -- you'd create one class that can be reused for many users. One of the class data members would distinguish the user, so each object instance of that class is for one user. But it's the same class.
Likewise, it's almost always better to create one table, and make sure the table includes a column to identify the user. It's simpler to add new users by INSERTing new rows into the table, instead of requiring new tables to be created.
There are exceptions to every rule, of course. You might have so many users that you must split the database over multiple database servers. Or you might have a very strict privacy requirement and separating the data into multiple tables is a good way to enforce it. But if you're just starting out with a small project, those exception cases probably don't affect you yet.

How to add new columns if needed

I am new to MySQL databases and I'm trying to create a web stock and production database, using PHP.
In this inventory software, I am trying to create a table in which products are created and also their components inserted. But if a product has a different number of components, I wanted to know if there is any way to add more components columns from the management page of the website.
Another thing is that these components are taken from another table, and as long as a new product order is created, the quantity of those used components should be subtracted from the components table. (but this is a major issue, solving the first issue should be enough for now).
Yes, you can add, or remove, columns from a database table at any time.
However, I would not do this. You have to try and design a database that can handle products with a varying number of component. Normally this would be done this way:
Create a table for your products.
Create a table for your components.
Create a linking table product_components, to indicate what components a product consists off.
See: Using linking tables for many to many relationships in MySQL
You need to know about relationships in mysql. There are basically 3 types(some may say 4 though) of relationships available in a relational database like mysql.
Here according to your description you can use
1 to many
many to many
relationship in your database. This may help you-
https://afteracademy.com/blog/what-are-the-different-types-of-relationships-in-dbms

What architecture should I use to build my own multi-tenancy system?

I already have a web app and now i'm trying to introduce a multi-tenancy concept in it. I was wondering how to manage many databases? I presently have a main database that holds a users table, and other impertinent tables for this question. But my main struggle is that I have a league table that has a 'database_name' which I use to set my MySQL connection with depending on the league the user choose.
Is there a better way to do this?
Thanks :)
The concept you are using is fine. You can also, for example, just use league.name (if league has a name) as the database name, or add some prefix/suffix to the name. I'm not sure if you are choosing one of multiple defined connections or are you changing the connection's database name in the config. I would suggest the second option.

Multi-database design application using Laravel 5.3 and Codeigniter

Friends, I am building a service application and would like to see a gross suggestion to achieve.
The core of the application is to manage research projects, hence it will have a group of users, who belong to an organization, who login and manage their own projects. Many organizations carry out such projects, which are identical in nature. The project management has identical database tables and schema (across institutions). I have designed a plan as follows:
Database-1: A common database users table (all institutions together) get authenticated by querying this table. This table has a institutional code corresponding to each user as a column.
Database-2 (institutional code as its name): Based on the institutional code, all the project management is done by connecting to this database. Within this database tables will be present.
....
Database-x (institutional code as its name).....
All databases will have identical schema and identical user interface. Institute wise management is easy this way.
Now, using Laravel, i know i can connect to multiple databases. I have done this in codeigniter 3 but trying to migrate to Laravel 5.3 as models architecture is different between Codeigniter 3 and Laravel 5.3.
Any better suggestions. I know my query is not a pure question but this question is about implementation of a many to many relation.
Since all institutions will have same modules and same functionalities why are you creating multiple databases? I have successfully done a similar project as you, a Centralised CMS which integrate all church under one diocese in CodeIgniter.
Just add an institution id in all tables and query your table operation with institution id every time. Adding multiple databases will definitely decrease your project performance and increase complexity. An institution table will track all your institutions.
If you need more details about database structure and implementation please comment below.
I have successfully worked on mutliple database and mutltiple domain application.
In that I have created one table "branches" which stored the multiple branches details
like its database name, domain name.
I have set the record as domain= "branch1", database="db_branch1" in table "branches"
Also set the middleware which check the valid domain name and allow to associated routes for domain "branch1".
Once the main common database authenticate the user creditials it connect to branch database in main connection.
It can not explain in very short method, here I just explain the work flow. If you need more details I will explain it.

How to work with encrypt database?

I have a new type project. Please help if you can. I have a user management project in which i have many tables lets say user table.
table user
fields user_id , user_f_name , user_l_name, user_username.. etc. this table is encrypted in real like
RM_999(this is name of encrypted table)
RM_0999, RM_1999 , RM_2999 , RM_3999...
I the same manner all tables and columns are encrypted for sake of security.
But i have yii project written in simple names like user_username (As it was already made project which i used for variouus project). But now i don't want to changed my code for that encrpted database. Is there is any way bye which i can use my written code without changing it.
Any help will be appreciated.
It depends on how your existing application code is written.
The below approach may solve your problem
In your project, if there are entity classes for all tables in DB which extends CActiveRecord then you can use attributeLables() so that you can map your existing column names to encrypted column names. (Assumed that your application code access that table attributes via labels).

Categories