1/ 首先需要在config/database.php文件中增加 数据库的相关配置  并为设置起名称

laravel 控制器内使用切换数据库

2/ 其次 在数据库中链接并使用

\DB::connection("mysql_other")->table("user")->find($id);
\DB::connection("mysql_other")->table("user")->where("id",$id)->update([]);

单纯的connection("mysql_other")不好判断是否正确链接,只有实际操作 然后打印才能体现出 是否正确链接

相关文章:

  • 2022-12-23
  • 2021-05-19
  • 2022-01-15
  • 2021-12-24
  • 2021-08-13
  • 2021-11-20
猜你喜欢
  • 2021-12-01
  • 2021-11-18
  • 2021-10-18
  • 2022-12-23
  • 2021-06-15
  • 2021-08-17
  • 2021-12-30
相关资源
相似解决方案