thinkphp5 master方法读取主库

2023-05-19,,

thinkphp5 master方法读取主库

默认是主库写,从库读。

   'rw_separate' => true,

在读写分离的情况下,默认第一个数据库配置是主服务器的配置信息,负责写入数据,如果设置了master_num参数,则可以支持多个主服务器写入。其它的都是从数据库的配置信息,负责读取数据,数量不限制。每次连接从服务器并且进行读取操作的时候,系统会随机进行在从服务器中选择。

    //读主库
    public function isrepeat($aid,$bid,$userid){
        if( intval($aid)<1 || intval($bid)<1 || intval($userid)<1 ){return false;}
        $count=Db::table('student')->master()->where("`aid`=$actid and `bid`=$bid and `userid`=$userid")->count();
        return $count;
    }

180605笔记  今天周五,大太阳,热,充实的下午,明天端午节,码农们,放假咯

The end

《thinkphp5 master方法读取主库.doc》

下载本文的Word格式文档,以方便收藏与打印。