国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

在webman中使用thinkorm組件配置主從多個(gè)數(shù)據(jù)庫(kù),連接錯(cuò)誤

9527

配置thinorm主從數(shù)據(jù)庫(kù),讀寫(xiě)異常

參考文檔:https://www.kancloud.cn/manual/think-orm/1258000 配置如下:

return [
    'default' => 'mysql',
    'connections' => [
        'mysql' => [
            // 數(shù)據(jù)庫(kù)部署方式:0 集中式(單一服務(wù)器),1 分布式(主從服務(wù)器)
            'deploy' =>  1,
            // 數(shù)據(jù)庫(kù)讀寫(xiě)是否分離 主從式有效(hostname第一個(gè)為主,其它為從;)
            'rw_separate' => true,
            // 讀寫(xiě)分離后 主服務(wù)器數(shù)量
            'master_num'      => 1,
            // 指定從服務(wù)器序號(hào)
            //'slave_no'        => '',
            // 模型寫(xiě)入后自動(dòng)讀取主服務(wù)器, 等價(jià)于 EloquentOrm 的 sticky 參數(shù)
            'read_master'     => false,
            // 數(shù)據(jù)庫(kù)類型
            'type' => 'mysql',
            // 服務(wù)器地址
            'hostname' => [getenv('DB1_HOST'),getenv('DB2_HOST')],
            // 數(shù)據(jù)庫(kù)名
            'database' => getenv('DB_NAME'),
            // 數(shù)據(jù)庫(kù)用戶名
            'username' => getenv('DB_USER'),
            // 數(shù)據(jù)庫(kù)密碼
            'password' => getenv('DB_PASSWORD'),
            // 數(shù)據(jù)庫(kù)連接端口
            'hostport' => getenv('DB_PORT'),
            // 數(shù)據(jù)庫(kù)連接參數(shù)
            'params' => [
                // 連接超時(shí)3秒
                \PDO::ATTR_TIMEOUT => 3,
            ],
            // 數(shù)據(jù)庫(kù)編碼默認(rèn)采用utf8
            'charset' => getenv('DB_CHARSET'),
            // 數(shù)據(jù)庫(kù)表前綴
            'prefix' => '',
            // 斷線重連
            'break_reconnect' => true,
            // 關(guān)閉SQL監(jiān)聽(tīng)日志
            'trigger_sql' => false,
            // 自定義分頁(yè)類
            'bootstrap' =>  ''
        ],
    ],
];

如上配置,使用了數(shù)組配置了兩個(gè)數(shù)據(jù)庫(kù):
'hostname' => [getenv('DB1_HOST'),getenv('DB2_HOST')],

錯(cuò)誤:

? php plugin/commerce/scripts/debug.php                                                                                                                                                                              ─╯
PHP Fatal error:  Uncaught ErrorException: Array to string conversion in /Volumes/webman/api/vendor/topthink/think-orm/src/db/PDOConnection.php:338
Stack trace:
#0 /Volumes/webman/api/vendor/topthink/think-orm/src/db/PDOConnection.php(338): {closure}(2, 'Array to string...', '/Volumes/Media/...', 338)
#1 /Volumes/webman/api/vendor/topthink/think-orm/src/db/PDOConnection.php(356): think\db\PDOConnection->getSchemaCacheKey('commercee.custo...')
#2 /Volumes/webman/api/vendor/topthink/think-orm/src/db/PDOConnection.php(411): think\db\PDOConnection->getSchemaInfo('customer_entity')
#3 /Volumes/webman/api/vendor/topthink/think-orm/src/db/PDOConnection.php(461): think\db\PDOConnection->getTableInfo('customer_entity', 'pk')
#4 /Volumes/webman/api/vendor/topthink/think-orm/src/db/Query.php(290): think\db\PDOConnection->getPk('customer_entity')
#5 /Volumes/webman/api/vendor/topthink/think-orm/src/db/BaseQuery.php(1279): think\db\Query->getPk()
#6 /Volumes/webman/api/vendor/topthink/think-orm/src/db/BaseQuery.php(1156): think\db\BaseQuery->parsePkWhere(1)
#7 /Volumes/webman/api/plugin/commerce/scripts/debug.php(8): think\db\BaseQuery->find(1)
#8 {main}

貌似是沒(méi)有讀取到 “deploy”分布式配置;請(qǐng)教各位,謝謝;

2531 1 0
1個(gè)回答

魯達(dá)

hostname 換成字符串格式,用逗號(hào)隔開(kāi)試試

  • 9527 2023-03-12

    經(jīng)過(guò)測(cè)試,hostname 更換成字符串逗號(hào)分隔可以正常工作;
    但是換成數(shù)組不可以;

年代過(guò)于久遠(yuǎn),無(wú)法發(fā)表回答
??