PHPackages                             sommer/wn-multidb-plugin - 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. sommer/wn-multidb-plugin

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

sommer/wn-multidb-plugin
========================

Plugin for WinterCMS to manage multiple databases

1.6.2(1y ago)1261MITPHP

Since Jul 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/phpiando/wn-multidb-plugin)[ Packagist](https://packagist.org/packages/sommer/wn-multidb-plugin)[ RSS](/packages/sommer-wn-multidb-plugin/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (9)DependenciesVersions (21)Used By (0)

WinterCMS Multi Databases
=========================

[](#wintercms-multi-databases)

[WinterCMS](http://wintercms.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 WinterCMS 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.

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 sommer/wn-multidb-plugin

```

### 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.

### Configuration .env

[](#configuration-env)

This is optional, but if you want to configure data from another connection in the tenants, you can put Multidb in the .env. If you don't put anything, it will automatically assume the access data from your main database server that is used in DB\_\*.

```
MULTIDB_CONNECTION=multidb
MULTIDB_HOST=127.0.0.1
MULTIDB_PORT=3306
MULTIDB_DATABASE=my_base
MULTIDB_USERNAME=root
MULTIDB_PASSWORD=

```

#### 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**

### 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 UsesTenantConnection

[](#trait-usestenantconnection)

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 \Sommer\Multidb\Traits\UsesTenantConnection;

	...
}
```

#### 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 UsesTenantConnection 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 \Sommer\Multidb\Traits\UsesMainConnection;

    ...
}
```

### Behaviors

[](#behaviors)

#### TenantSelectionBehavior

[](#tenantselectionbehavior)

The TenantSelectionBehavior class added to the controller will allow the user to choose a Tenant to view once they try to access this controller (if they haven't selected one previously). At this point, this behavior adds a button next to the user's image to the navigation menu, which allows them to change the selected Tenant.

```
class Summaries extends Controller
{
    /**
     * @var array
     */
    public $implement = [
        'Backend\Behaviors\ListController',
        'Backend\Behaviors\FormController',
        'Sommer\MultiDB\Behaviors\TenantSelectionBehavior', //  [
            'Sommer\Multidb\Models\File',
            'softDelete' => true,
        ],
    ];

    ...
}
```

License
-------

[](#license)

This plugin is released under the [MIT License](https://opensource.org/license/mit/). You can freely use, modify, and distribute it in your projects, but please keep the original license intact.

Sponsors
--------

[](#sponsors)

If you find this plugin useful and would like to support its development, consider sponsoring the project. Your contributions help keep the project alive and improve its features. You can sponsor the project on [GitHub Sponsors](https://github.com/sponsors/phpiando).

Contributing
------------

[](#contributing)

Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request on the [GitHub repository](https://github.com/phpiando/wn-multidb-plugin).

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance50

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity49

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 ~18 days

Recently: every ~2 days

Total

20

Last Release

366d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12565400?v=4)[Roni Sommerfeld](/maintainers/phpiando)[@phpiando](https://github.com/phpiando)

### Embed Badge

![Health badge](/badges/sommer-wn-multidb-plugin/health.svg)

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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