您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

laravel連接多個不同數據庫的單例類

2025/10/12 7:41:14发布18次查看
在連接多個不同數據庫時,需要寫多個連接,爲了簡化該操作,可以使用該基類,不同的數據庫只要建立好相對應的類繼承該類,就可以使用orm模型進行操作了。
class singletoninstance { protected static $instances = []; protected static $table = null; protected static $connection = null; public function __construct() { if(!isset(static::$instances[static::class])){ if(is_null(self::$table) || is_null(self::$connection)) { throw new \exception('not defined property'); } static::$instances[static::class] = db::connection(self::connection)->table(self::$table); } } public static function getdb() { return static::$instances[static::class]; }}
以上就是laravel連接多個不同數據庫的單例類的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product