dousi2013 2017-10-16 16:51
浏览 49

Laravel - 一次多个数据库[重复]

This question already has an answer here:

I am creating a Laravel/latest-version application which requires several hundreds of sql table to be created to serve the job. There will again be hundreds of clients who's data will be inserted multiple times (1000 rows per client or more in some tables) in these table. To eliminate confusion, I want a general/common-database for common information and separate Database for each client for specific information and would like to create new DB when a client is added. Can this be done in Laravel (dealing with multiple Databases at once) or is there any other PHP framework which can serve this purpose better? Much obliged for your help.

</div>
  • 写回答

1条回答 默认 最新

  • dsxz84851 2017-10-16 18:07
    关注

    Well most of the times, this is an architectural flaw because the db isn't designed well. Normally this kind of issue is faced due to the reason that all your tables are normalized. Normalization is good for small applications but for data rich applications you have to judge which fields need to be normalized and which doesn't need normalization. You can save lots of tables and fields with denormalization. As a rule of thumb anything that you dont have to query directly or via join can be denormalized.

    Anyways it is possible to have multiple databases attached to a single laravel application. I have done this once on a huge application.

    So the idea is that before every eloquent query you will have to set the db connection.

    $someModel->setConnection('mysql2');
    

    You can find more information about it here

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用