PHPackages                             techmobi/multidb - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. techmobi/multidb

ActiveOctober-plugin[Database &amp; ORM](/categories/database)

techmobi/multidb
================

Plugin for OctoberCMS allowing to assign different database to different domains

v1.0.7(5y ago)32894[1 issues](https://github.com/over12/oc-techmobi-multidb/issues)MITPHP

Since Jan 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/over12/oc-techmobi-multidb)[ Packagist](https://packagist.org/packages/techmobi/multidb)[ RSS](/packages/techmobi-multidb/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (4)Used By (0)

OctoberCMS Multi Databases
==========================

[](#octobercms-multi-databases)

[OctoberCMS](http://octobercms.com/) Plugin to create SaaS applications in different databases, making it easier to manage multiple clients. To develop this plugin I reused several classes that OctoberCMS itself has, trying to create the simplest code possible.

**Important**This plugin is still in the testing and development stages, use at your own risk.

REQUERIMENTS
------------

[](#requeriments)

[Multisite](https://octobercms.com/plugin/voipdeploy-multisite)

Usage
-----

[](#usage)

### Installation

[](#installation)

You can install this plugin either via composer.

#### With Composer

[](#with-composer)

Execute below at the root of your project.

```
composer require techmobi/multidb

```

#### Configuring file database.php

[](#configuring-file-databasephp)

You will need to make a small change to the file in `config/database.php`

```
...

'original' => env('DB_CONNECTION', 'mysql'), //  [
	...

    //ADD THIS ARRAY
	'multidb' => [
        'driver' => 'mysql',
        'engine' => 'InnoDB',
        'host' => env('MULTIDB_HOST', 'localhost'),
        'port' => env('MULTIDB_PORT', 3306),
        'database' => env('MULTIDB_DATABASE', 'database'),
        'username' => env('MULTIDB_USERNAME', ''),
        'password' => env('MULTIDB_PASSWORD', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'varcharmax' => 191,
    ],

	...
]
...
```

### Settings MultiDB - Backend

[](#settings-multidb---backend)

To use MultiDB you will need to follow the steps below.

**Important**It is necessary to have a user in the database who can Read, Edit and Update data, as well as create new databases.

#### MultiDB Plugin

[](#multidb-plugin)

First Navigate to `Settings -> MultiDB -> Settings Plugin`, in this place you can configure the prefixes that the databases may have, configure what will be the names of each databases, and also, you can select which plugins will be replicated for the new created instances.

**Save changes to update data**

#### Added new Hosts MultiDB

[](#added-new-hosts-multidb)

Navigate to `Settings -> MultiDB -> Hosts`, in this place you can add new databases and list which domains will be used. At this point comes the multisite relationship. With this configuration, it will be possible to identify the databases according to each domain accessed.

### Using in PHP Code

[](#using-in-php-code)

After making the configurations mentioned above, it is necessary to edit the models of the plugins.

#### Trait UsesMultiConnection

[](#trait-usesmulticonnection)

This trait is responsible for managing the data that will be saved in the databases. It will be necessary to add the following trait to all models that have the replicated database, example below:

```
class Product extends Model
{
	use \Techmobi\Multidb\Traits\UsesMultiConnection;

	...
}
```

#### Trait UsesMainConnection

[](#trait-usesmainconnection)

This Trait allows you to relate a table from the main database to the child database, for example, you have a Customers plugin, this plugin is using the UsesMultiConnection trait, however ou have a Core plugin that has a Country Model, this plugin you are not replicating, but you need to relate the `country_id` attribute of the customers table to the country table, in this situation there would be an error because MultiDB change connections momentarily, so as not to have a problem, you need to add in your model Country the trait below.

```
class Product extends Model
{
    use \Techmobi\Multidb\Traits\UsesMainConnection;

    ...
}
```

#### BONUS: MultiFiles with MultiDB

[](#bonus-multifiles-with-multidb)

If in case you want to save the files in the new database, you will need to use the model `Techmobi\Multidb\Models\File`, example use:

```
class Product extends Model
{
	use \Techmobi\Multidb\Traits\UsesMultiConnection;

	...

	public $attachMany = [
        'images' => [
            'Techmobi\Multidb\Models\File',
            'softDelete' => true,
        ],
    ];

    ...
}
```

##### MediaLibrary

[](#medialibrary)

For now I was unable to make a class to manage MediaLibrary, however you can change the file `System\Classes\MediaLibrary`, adding the following codes:

```
class MediaLibrary
{
    use \October\Rain\Support\Traits\Singleton;
    use \Techmobi\Multidb\Traits\UsesMultiConnection;

    ...

    protected function init()
    {
        $this->getDomainData();

        if (!empty($this->getDatabaseName())) {
            $this->storageFolder = "/{$this->getDatabaseName()}/media";
            $this->storagePath = "/storage/app/{$this->getDatabaseName()}/media";
        } else {
            $this->storageFolder = self::validatePath(Config::get('cms.storage.media.folder', 'media'), true);
            $this->storagePath = rtrim(Config::get('cms.storage.media.path', '/storage/app/media'), '/');
        }

        $this->ignoreNames = Config::get('cms.storage.media.ignore', FileDefinitions::get('ignoreFiles'));

        $this->ignorePatterns = Config::get('cms.storage.media.ignorePatterns', ['^\..*']);

        $this->storageFolderNameLength = strlen($this->storageFolder);
    }
    ...
}
```

Events Change Schema
--------------------

[](#events-change-schema)

An event has been added to force a database schema change, how does it work? Imagine that you have several databases created, however you do not want to be connecting at each URL, with that a database session was implemented, and below there is an event that you can pass a schema.

```
    Event::fire('techmobi.schema.set', 'my_awesome_schema');
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Total

2

Last Release

1930d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b291319098f6d745cd7e7edcf533b72820e5b4114c9b8ab6003a51dc94b61bfe?d=identicon)[phpiando](/maintainers/phpiando)

### Embed Badge

![Health badge](/badges/techmobi-multidb/health.svg)

```
[![Health](https://phpackages.com/badges/techmobi-multidb/health.svg)](https://phpackages.com/packages/techmobi-multidb)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
