Skip to content

Instantly share code, notes, and snippets.

View prsws's full-sized avatar

José F. Reyes-Santana prsws

  • PR Software Services LLC
  • San Juan, Puerto Rico
  • 15:55 (UTC -04:00)
View GitHub Profile
@prsws
prsws / gist:8162386
Created December 28, 2013 18:18
A Multi-Tenant Strategy using Yii and MySQL

Introduction

This article describes an implementation of multi-tenancy using Yii and MySQL. “Multi-tenancy” is but one (yet crucial) aspect of SaaS applications; refer to the IBM document Convert your web application to a multi-tenant SaaS solution for more information on what else makes a webapp a SaaS application.

Moreover, there are three main architectures for multi-tenant databases: separate database, separate schemas and a single database. Refer to the Microsoft document Multi-Tenant Data Architecture for more information.

As MySQL doesn’t have schemas (at least the same way MS SQL Server and Oracle do) the only choices are a separate database for each tenant and single database with “commingled” tenant data. SaaS applications with a relatively small number of tenants can be easily managed with a database for each one, but for large numbers of tenants its