PHPackages                             symbiotic/database - 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. symbiotic/database

ActiveLibrary[Database &amp; ORM](/categories/database)

symbiotic/database
==================

Database connection configurator with the ability to define a connection by namespace.

1.4.2(3y ago)0752BSD-3-ClausePHPPHP &gt;=8.0

Since Mar 12Pushed 3y agoCompare

[ Source](https://github.com/symbiotic-php/database)[ Packagist](https://packagist.org/packages/symbiotic/database)[ RSS](/packages/symbiotic-database/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (2)

Symbiotic Database
==================

[](#symbiotic-database)

README.RU.md [РУССКОЕ ОПИСАНИЕ](https://github.com/symbiotic-php/database/blob/master/README.RU.md)

**Database connection configuration package with the ability to select a connection depending on the namespace.**

Installing
----------

[](#installing)

```
composer require symbiotic/database

```

Description
-----------

[](#description)

The package contains two main interfaces and a manager:

- `ConnectionsConfigInterface` - Responsible for storing connections
- `NamespaceConnectionsConfigInterface` - Responsible for storing namespace connections
- `DatabaseManager` - Manager, contains all two interfaces, \\ArrayAccess , \\Stringable
-

### Usage

[](#usage)

Initializing Connections:

```
    $config = [
       'default' => 'my_connect_name',
        // Namespace connections
        'namespaces' => [
           '\\Modules\\Articles' => 'mysql_dev',
        ]
       'connections' => [
            'my_connect_name' => [
                'driver' => 'mysql',
                'database' => 'database',
                'username' => 'root',
                'password' => 'toor',
                'charset' => 'utf8mb4',
                'collation' => 'utf8mb4_unicode_ci',
                'prefix' => '',
            ],
            'mysql_dev' => [
             // ....
            ],
        ]
    ];

  // Building from an array
  $manager = \Symbiotic\Database\DatabaseManager::fromArray($config);

  // Building via constructor
  $manager = new \Symbiotic\Database\DatabaseManager(
            new \Symbiotic\Database\ConnectionsConfig($config['connections'], $config['default']),
            new \Symbiotic\Database\NamespaceConnectionsConfig($config['namespaces']) // необязательно
        );
```

Methods `ConnectionsConfigInterface` и `\ArrayAccess`:

```
/**
 * @var \Symbiotic\Database\DatabaseManager $manager
 */
// Getting all connections
$connections = $manager->getConnections();

// Default Connection
$defaultConnection = $manager->getDefaultConnectionName();

// Checking if a connection config exists
$bool = $manager->hasConnection('my_connect_name');
$bool = isset($manager['my_connect_name']);

// Getting connection data
$connectionData = $manager->getConnection('my_connect_name');
$connectionData = $manager['my_connect_name'];

// Retrieving connection data by namespace, if search engine by namespaces is enabled (description below)
$connectionData = $manager->getConnection(\Modules\PagesApplication\Models\Event::class);

// Adding a connection
$manager->addConnection(
         [
            'driver' => 'mysql',
            'database' => 'test_db',
            'username' => 'root',
            'password' => 'toor',
            //....
        ],
        'test_connection'
);
$manager['my_connect_name'] = [
//....
];

// Deleting a connection by name
$manager->removeConnection('test_connection');
unset($manager['test_connection']);
```

Methods `NamespaceConnectionsConfigInterface`:

```
/**
 * @var \Symbiotic\Database\DatabaseManager $manager
 */

// Is the connection search by namespace active?
$bool = $manager->isActiveNamespaceFinder();

// Enable/disable search
$manager->activateNamespaceFinder(false);

// Adding a connection for a module
$manager->addNamespaceConnection('\\Modules\\PagesApplication', 'test_connection');

// Getting the name of the connection by class, if disabled, it will return null
$pagesConnectionName = $manager->getNamespaceConnection(\Modules\PagesApplication\Models\Event::class); // return `test_connection`

// Automatic connection search in the call stack, if disabled, returns null
$connectionData = $manager->findNamespaceConnectionName();
```

Behavioral Features
-------------------

[](#behavioral-features)

Additionally, there is a smart \_\_toString() method. If namespace search is enabled `isActiveNamespaceFinder()`, it looks for a connection by namespace via the `findNamespaceConnectionName()` method or returns the default connection from the `getDefaultConnectionName()` method

#### Also pay attention to the behavior when the definition of connections by namespaces is disabled!

[](#also-pay-attention-to-the-behavior-when-the-definition-of-connections-by-namespaces-is-disabled)

Examples:

```
// Configuration part
'default' => 'my_connect_name',
// Packet Connections
'namespaces' => [
   '\\Modules\\Articles' => 'mysql_dev',
]
/**
 * @var \Symbiotic\Database\DatabaseManager $manager
 */
 // Installed Namespace from config
namespace  Modules\Articles\Models {

$objectConnectionName = (string)$manager; //  mysql_dev (namespace connection)
$objectConnectionData = $manager->getConnection(__NAMESPACE__); //  mysql_dev config  (namespace connection)
$objectConnectionName = $manager->getNamespaceConnection(__NAMESPACE__); //  mysql_dev  (namespace connection)
$connectionData = $manager->findNamespaceConnectionName(); //  mysql_dev  (namespace connection)

// turn off detection by namespaces
$manager->activateNamespaceFinder(false);

$objectConnectionName = (string)$manager; //  my_connect_name (default)
$objectConnectionData = $manager->getConnection(__NAMESPACE__); //  NULL
$objectConnectionName = $manager->findNamespaceConnectionName();//  NULL
$objectConnectionName = $manager->getNamespaceConnection(__NAMESPACE__); // NULL
// Namespace connection can be requested directly from the config
$objectConnectionName = $manager->getNamespacesConfig()->getNamespaceConnection(__NAMESPACE__); // mysql_dev (namespace connection)

}
// Любой другой неймспейс
namespace  Modules\NewSpace\Models {

$objectConnectionName = (string)$manager; //  my_connect_name  (default)
$objectConnectionData = $manager->getConnection(__NAMESPACE__); //  NULL
$objectConnectionName = $manager->findNamespaceConnectionName();//  NULL
$objectConnectionName = $manager->getNamespaceConnection(__NAMESPACE__); // NULL
}
```

For Symbiotic Applications
--------------------------

[](#for-symbiotic-applications)

Symbiotic framework applications have a provider to automatically establish a connection from the application settings relative to the base nemspace of the package.

1. To add a database selection field, create a field named `database_connection_name` in the package settings fields:

```
// symbiotic.json
{
  "settings_fields": [
    {
      "label": "App Database",
      "name": "database_connection_name",
      "type": "settings::database"
    }
    /// Other settings fields...
  ]
}
```

2. In the application section `"app"` add the provider \\Symbiotic\\Database\\AppNamespaceConnectionProvider

```
// symbiotic.json
{
  "app": {
    "id": "my_app",
    //....
    "providers": [
      "\\Symbiotic\\Database\\AppNamespaceConnectionProvider" // Added provider
    ]
    /// More app settings...
  }
}
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

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

Total

3

Last Release

1132d ago

### Community

Maintainers

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

### Embed Badge

![Health badge](/badges/symbiotic-database/health.svg)

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

###  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)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

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

Reliese Components for Laravel Framework code generation.

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

PHPackages © 2026

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