dongzu0742 2013-01-30 19:08
浏览 201

使用PHP和MySQL进行多租户

I have a web application built on CodeIgniter PHP, a MYSQL database, and we use PHPActiveRecords. We keep growing and expanding and now need to offer the application whitelabeled. I have most of that done the only problem I am running into is how to handle the database. I don't want to have two database connections because a good deal of the data between the two site will be shared. I was researched Multitenancy and it sounds like a great option, but if I have to go rewrite every ActiveRecord find to have a condition where tenant_id = 'this site' and then have to train my employees to do the same when they now write code, it isn't scalable. Does anyone have any ideas of how to either A) integrate multitenancy into PHPActiveRecords without a lot of modifications, or B) a better solution then multitenancy.

Thank you in advance.

  • 写回答

1条回答 默认 最新

  • douxiangbiao1899 2013-01-30 19:11
    关注

    Depending on how many clients you have, you could create a schema per client, on one host. Prefix the table names for your common tables with your common database names, and rely on the client queries to use the default database.

    Your entrypoint may do something like:

    $pdo->query('USE client_12345');
    

    And your queries may be something like:

    $pdo->query('SELECT * FROM clientspecificdata WHERE ...');
    

    And

    $pdo->query('SELECT * FROM common.data WHERE ...');
    

    Note on this: this carries a relatively high risk of exposing data to the wrong clients. Be sure this is appropriate for your scenario. You may be much better off with multiple connections.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料