antidot-fw/dbal-adapter

Antidot 框架的 Doctrine DBAL 适配器库。

1.0.3 2021-01-10 15:16 UTC

This package is auto-updated.

Last update: 2024-08-30 01:34:16 UTC


README

Latest Version on Packagist Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status

Antidot 框架的 Doctrine DBAL 适配器库。

配置

它使用在Doctrine DBAL 项目文档中定义的配置参数。

<?php

declare(strict_types=1);

$config = [
    'dbal' => [
        'connections' => [
            'default' => [
                'url' => 'mysql://user:secret@localhost/mydb',
            ],
            'other_connection' => [
                'dbname' => 'otherdb',
                'user' => 'user',
                'password' => 'secret',
                'host' => 'localhost',
                'driver' => 'pdo_mysql',
            ],
        ],
    ],
];

用法

使用 Laminas 组件安装程序

如果你的应用程序使用 PSR-11 容器以及 Laminas 组件安装程序,则无需额外操作即可正常工作,只需安装即可。

作为独立包

<?php

declare(strict_types=1);

use Antidot\Persistence\DBAL\Container\DBALConnectionFactory;
use Psr\Container\ContainerInterface;

/** @var ContainerInteface $container */
$container->set('config', $config);
$factory = new DBALConnectionFactory();
$defaultConnection = $factory->__invoke($container);
$theOtherConnection = $factory->__invoke($container, 'other_connection');