1. Go to this page and download the library: Download symbiotic/database library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
symbiotic / database example snippets
$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']) // необязательно
);
/**
* @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']);
/**
* @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();