mkubenka/yii2-db-reconnect

Yii2 数据库自动重连

1.1.1 2019-09-15 10:48 UTC

This package is not auto-updated.

Last update: 2024-09-29 02:52:06 UTC


README

Latest Stable Version

灵感来源

https://github.com/xjflyttp/yii2-db-reconnect

安装

composer require mkubenka/yii2-db-reconnect

"require": {
    "mkubenka/yii2-db-reconnect": "~1.0"
},

配置

'db' => [
    'class' => 'mkubenka\dbreconnect\mysql\Connection',
    'reconnectMaxCount' => 2,
    'dsn' => 'mysql:host=127.0.0.1;dbname=test',
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',
],

日志记录

'log' => [
    'targets' => [
        [
            'class' => 'yii\log\FileTarget',
            'levels' => ['error', 'info'],
            'maxLogFiles' => 20,
            'maxFileSize' => 2048,
            'categories' => [
                'mkubenka\dbreconnect\*',
            ],
            'logFile' => '@frontend/runtime/logs/dbreconnect.log',
        ],
    ],
],

已知限制

此方法仅适用于非事务性语句。