ppypp伦理天堂,91手机在线视频,免费在线观看黄色毛片,夜夜穞天天穞狠狠穞AV美女按摩

聯(lián)系官方銷售客服

1835022288

028-61286886

投訴 已解決 使用了thinkphp的Db,要怎么鏈接多個數(shù)據(jù)庫呢? 4 0
迅睿CMS版本:4.5.2

框架中可以鏈接多個數(shù)據(jù)庫,如果使用了thinkphp的Db,要怎么鏈接多個數(shù)據(jù)庫呢?

還是一樣的方法嗎?我在config/database.php添加了多個數(shù)據(jù)庫鏈接,按照thinkphp的方法寫,卻鏈接不上

解決方案


  • 這個文件改成下面的內容試一試

    <?php namespace Config;
    /**
     * {{www.zbshanke.com}}
     * {{迅睿內容管理框架系統(tǒng)}}
     * 本文件是框架系統(tǒng)文件,二次開發(fā)時不可以修改本文件
     **/
    
    use CodeIgniter\Database\Config;
    
    /**
     * Database Configuration
     */
    class Database extends Config
    {
        /**
         * The directory that holds the Migrations
         * and Seeds directories.
         * @var string
         */
        public $filesPath = WRITEPATH.'database/';
    
        /**
         * Lets you choose which connection group to
         * use if no other is specified.
         *
         * @var string
         */
        public $defaultGroup = 'default';
    
        /**
         * The default database connection.
         *
         * @var array
         */
        public $default = [
            'DSN'          => '',
            'hostname'     => 'localhost',
            'username'     => '',
            'password'     => '',
            'database'     => '',
            'DBDriver'     => 'MySQLi',
            'DBPrefix'     => '',
            'pConnect'     => false,
            'DBDebug'     => true,
            'cacheOn'     => true,
            'cacheDir'     => WRITEPATH.'database/',
            'charset'      => 'utf8mb4',
            'DBCollat'     => 'utf8mb4_general_ci',
            'swapPre'      => '',
            'encrypt'      => false,
            'compress'     => false,
            'strictOn'     => false,
            'failover'     => []
        ];
    
        //--------------------------------------------------------------------
    
        public function __construct()
        {
            parent::__construct();
    
            $db = [];
            require ROOTPATH.'config/database.php';
    
            foreach ($this->default as $p => $t) {
                foreach ($db as $name => $v) {
                    $this->$name[$p] = isset($v[$p]) ? $v[$p] : $t;
                }
            }
    
            // 判斷數(shù)據(jù)庫名稱的規(guī)范性
            if (is_numeric($this->default['database'])) {
                exit('數(shù)據(jù)庫名稱不能是數(shù)字');
            } elseif (strpos($this->default['database'], '.') !== false) {
                exit('數(shù)據(jù)庫名稱不能存在.號');
            }
    
            // Thinkphp數(shù)據(jù)庫配置
            if (is_file(dirname(COMPOSER_PATH).'/topthink/think-orm/src/DbManager.php')) {
    			$cfg = [
                    // 默認數(shù)據(jù)連接標識
                    'default'     => 'default',
                    // 數(shù)據(jù)庫連接信息
                    'connections' => [
                    ],
                ];
    			foreach ($db as $name => $v) {
    				$cfg['connections'][$name] = [
    					// 數(shù)據(jù)庫類型
    					'type'     => 'mysql',
    					// 主機地址
    					'hostname' => $v['hostname'],
    					// 用戶名
    					'username' => $v['username'],
    					'password' => $v['password'],
    					// 數(shù)據(jù)庫名
    					'database' => $v['database'],
    					// 數(shù)據(jù)庫編碼默認采用utf8mb4
    					'charset'  => 'utf8mb4',
    					// 數(shù)據(jù)庫表前綴
    					'prefix'   => $v['DBPrefix'],
    					// 數(shù)據(jù)庫調試模式
    					'debug'    => true,
    				];
                }
                \think\facade\Db::setConfig($cfg);
            }
    
        }
    
        //--------------------------------------------------------------------
    
    
    }
    滿意答案
    開源積分+10
  • 回復@迅??蚣苈?lián)合創(chuàng)始人 謝謝,可行

  • 回復@開黑嗎我玩輔助 可行

  • @迅??蚣苈?lián)合創(chuàng)始人:謝謝,可行