An open API service indexing awesome lists of open source software.

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.

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);
```