PHP Laravel框架 多数据库连接方法

1. 在config 下database.php中配置数据库连接  然后在使用时直接用connection指向该连接即可

DB::connection('connections-theatre')->table('tb_order_ticket')->insert($data);

 2. 在model中重定向到指定数据库连接

<?php

namespace App\ModelTh;class ThBase extends Base
{

    protected $connection = 'connections-theatre';

    public static function ******(){
        ......
    }

}

猜你喜欢

转载自www.cnblogs.com/dereckbu/p/9293668.html