方法1(推荐):
DB::connection('write')->table('a')->get();
#在 config/database.php 配置文件里面配置读库 'write' => [ 'driver' => 'mysql', 'host' => env('DB_WRITE_HOST', 'localhost'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, ], #手动链接主库查询 DB::connection('write')->table('a')->get();
方法2:
DB::table('a')->lock()->get();
方法3:
$sql = 'select * from a'; DB::select($sql, [], false);
方法4: 仅供参考
$pdo = DB::connection()->getPdo(); $data=DB::connection()->setPdo($pdo)->table('a')->get();
方法5(推荐):
$sql = 'select * from a'; DB::selectFromWriteConnection($sql);