Are there any PHP structures (e.g. CodeIgniter) that support database connections for each user account for use in the Multi-tenant database?

I am developing a SaaS application with multiple tenants, and I have found several sites that describe a reliable way to split data using tenantIDs and updatable views. For example This blog post

It all depends on the possibility of authenticating user accounts from the table of main users, and then these credentials for a specific user are used with their corresponding database connections. Thus, views can pull out the user ID and match it with the tenantID to display that user view. However, most PHP frameworks are typically very static when connected to a database (stored in text-based configuration files). They do not seem to agree.

Does anyone know: a) how to make CodeIgniter handle this gracefully? b) another PHP framework that can?

+6
database php codeigniter multi-tenant
source share
3 answers

At a terribly basic level you can do this:

http://philsturgeon.co.uk/blog/2009/06/How-to-Multi-site-CodeIgniter-Set-up

Expand it as needed, or move the logic to MY_Controller for more flexibility.

+4
source share

There is a topic discussing this on the Code Igniter forums.

http://codeigniter.com/forums/viewthread/165227/#846845

It looks like you configured your user database as your main database in the configuration file, then you create a configuration array for the new connection for the user based on the information in this user database. So, I think you need to at least save the database name in the user database.

Not sure how well this works, since I havenโ€™t had a chance to try it yet.

Sorry if this is not exactly what you were looking for, but it should give you an idea of โ€‹โ€‹the Code Igniter approach.

+1
source share
0
source share

All Articles