https://github.com/juborajnaofel/multidb-tenancy
This repository provides a lightweight, raw PHP implementation for multi-tenancy support in web applications. It offers a flexible approach for managing multiple databases, allowing each tenant to have its own isolated database schema while sharing the same codebase.
https://github.com/juborajnaofel/multidb-tenancy
database multi multi-tenancy mysql php tenancy
Last synced: over 1 year ago
JSON representation
This repository provides a lightweight, raw PHP implementation for multi-tenancy support in web applications. It offers a flexible approach for managing multiple databases, allowing each tenant to have its own isolated database schema while sharing the same codebase.
- Host: GitHub
- URL: https://github.com/juborajnaofel/multidb-tenancy
- Owner: juborajnaofel
- License: mit
- Created: 2024-01-30T08:47:58.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-02T14:53:18.000Z (over 2 years ago)
- Last Synced: 2025-01-10T17:18:11.142Z (over 1 year ago)
- Topics: database, multi, multi-tenancy, mysql, php, tenancy
- Language: PHP
- Homepage:
- Size: 30.3 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# multidb-tenancy
config database and domains in ./config/config.php
```php
$dbConfig = [
"DB_CONNECTION" => "mysql",
"DB_HOST"=>"127.0.0.1",
"DB_PORT"=>3306,
"DB_DATABASE"=>"testtenancy",
"DB_USERNAME"=>"root",
"DB_PASSWORD"=> "",
];
$domainConfig = [
"APP_URL" => '',
"CENTRAL_DOMAIN" => ''
];
```
access current subdomain in index.php
```php
$subdomain = $tenancy->currentSubdomain();
```
create a tenant in index.php
```php
$tenancy->createTenant($dbConfig['DB_DATABASE'].'_'.$subdomain);
```
switch to tenant database in index.php
```php
$db->switchTenant($dbConfig['DB_DATABASE'].'_'.$subdomain);
```