迅睿CMS框架是一款PHP8高性能·簡單易用的CMS開源開發(fā)框架,基于MIT開源許可協(xié)議發(fā)布,免費(fèi)且不限制商業(yè)使用,是免費(fèi)開源的產(chǎn)品,以萬端互聯(lián)為設(shè)計(jì)理念,支持的微信公眾號、小程序、APP客戶端、移動端網(wǎng)站、PC網(wǎng)站等多終端式管理系統(tǒng)。
聯(lián)系官方銷售客服
1835022288
028-61286886
框架中可以鏈接多個(gè)數(shù)據(jù)庫,如果使用了thinkphp的Db,要怎么鏈接多個(gè)數(shù)據(jù)庫呢?
還是一樣的方法嗎?我在config/database.php添加了多個(gè)數(shù)據(jù)庫鏈接,按照thinkphp的方法寫,卻鏈接不上
這個(gè)文件改成下面的內(nèi)容試一試
<?php namespace Config; /** * {{223987.com}} * {{迅睿內(nèi)容管理框架系統(tǒng)}} * 本文件是框架系統(tǒng)文件,二次開發(fā)時(shí)不可以修改本文件 **/ 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 = [ // 默認(rèn)數(shù)據(jù)連接標(biāo)識 'default' => 'default', // 數(shù)據(jù)庫連接信息 'connections' => [ ], ]; foreach ($db as $name => $v) { $cfg['connections'][$name] = [ // 數(shù)據(jù)庫類型 'type' => 'mysql', // 主機(jī)地址 'hostname' => $v['hostname'], // 用戶名 'username' => $v['username'], 'password' => $v['password'], // 數(shù)據(jù)庫名 'database' => $v['database'], // 數(shù)據(jù)庫編碼默認(rèn)采用utf8mb4 'charset' => 'utf8mb4', // 數(shù)據(jù)庫表前綴 'prefix' => $v['DBPrefix'], // 數(shù)據(jù)庫調(diào)試模式 'debug' => true, ]; } \think\facade\Db::setConfig($cfg); } } //-------------------------------------------------------------------- }
這方法可行嗎
回復(fù)@迅??蚣苈?lián)合創(chuàng)始人 謝謝,可行
回復(fù)@開黑嗎我玩輔助 可行
這個(gè)文件改成下面的內(nèi)容試一試
這方法可行嗎
回復(fù)@迅??蚣苈?lián)合創(chuàng)始人 謝謝,可行
回復(fù)@開黑嗎我玩輔助 可行