Revision #37                                    has been created by  CeBe                                    on Apr 14, 2014, 6:13:18 AM with the memo:
 CeBe                                    on Apr 14, 2014, 6:13:18 AM with the memo:
                                
                                
                                    changed yii version                                
                                                                    « previous (#36)                                                                                            
                            Changes
                            
    Title
    unchanged
    A Multi-Tenant Strategy using Yii and MySQL
    Category
    unchanged
    How-tos
    Yii version
    unchanged
    
    Tags
    unchanged
    saas, multi-tenant
    Content
    unchanged
    [...]
So, for internal operations, app staff users (which would have the root credentials anyway) or if the user is not logged in (a “guest”) the default db connection “root” prevails; otherwise it is overriden in every app request by the user tenant’s credentials. Remember, tenant users only interact with the filtered MySQL views and not directly with any tables, except perhaps retrieving from system wide tables that don't hold any tenant data such as countries/cities/units-of-measure/car makes/etc; that is reserved for app staff and internal purposes only. Code your Yii controllers and views accordingly.  
That’s it. It took me a long time to figure all of this out but it has been working successfully in a production app for six months already, with no problems. Enjoy!
PS - I'm working on a MS SQL Server implementation that uses schemas, filegroups and all that goodness to achieve tenant separation without the headache of commingled backups and disaster recovery. Stay tuned!