大家好,又见面了,我是你们的朋友全栈君。
1、配置.env 文件
NECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=root
DB_PASSWORD=
DB_HOST_EXREND=127.0.0.1
DB_PORT_EXREND=3306
DB_DATABASE_EXREND=database_center
DB_USERNAME_EXREND=root
DB_PASSWORD_EXREND=
2、配置 config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'mysql_extend' => [
'driver' => 'mysql',
'host' => env('DB_HOST_EXREND', 'localhost'),
'port' => env('DB_PORT_EXREND', '3306'),
'database' => env('DB_DATABASE_EXRENDR', 'forge'),
'username' => env('DB_USERNAME_EXREND', 'forge'),
'password' => env('DB_PASSWORD_EXREND', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
3, 通过DB进行操作:
DB::connection("mysql_extend")->table("user")->find($id);
4, 通过model进行操作,
public $connection = 'mysql_extend';
public $table = "user";
User::find($id);
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/105853.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...