我正在开发一个多租户应用程序,并且已经快完成了。
目前,我每个客户使用一个数据库 - 每次复制它并根据 $_SERVER['http_host'] 进行命名...
每个数据库的很多表都不会更改,并且包含相同的信息。
我想要一个包含这些信息的主应用程序数据库,包括客户端列表以及数据库的名称。然后,该数据库将用于选择正确的客户数据库...
这可能吗?有人可以为我指出合适的教程吗?
谢谢
I have a multi-tenancy application that I am developing and I'm nearly there.
Currently I am using one database per customer - copying it each time and naming depending based on $_SERVER['http_host']...
A lot of the tables each database never change, and contain the same information.
I would like to have a main application database that contains this information, including a list of clients and what there database is called. This database would then be used to select the correct customers database...
Is this possible and can anyone point me in the direction of a suitable tutorial?
Thanks
发布评论
评论(1)
好的,所以您的“管理”数据库和“客户”数据库需要不同的数据库配置。
使用此页面中的示例生成这些单独的配置:
http://ellislab.com/codeigniter /user_guide/database/configuration.html
然后,在你的主控制器中(请告诉我你扩展了 MY_Controller.php 而不是只需使用 CI_Controller.php),您将需要读取“admin”数据库并获取所有客户端信息。然后,您需要为此客户端数据库生成一个
$config
数组,并使用新的$config
数组重新加载数据库:然后您将建立与客户端的连接数据库。
注意
如果您需要来回连接到两个数据库,那么您可以按照本页的说明连接到多个数据库:http://ellislab.com/codeigniter/user_guide/database/connecting.html
OK, so you'll need different database configs for your "administrative" database and your "customer" databases.
Use the examples from this page to generate those separate configs:
http://ellislab.com/codeigniter/user_guide/database/configuration.html
Then, in your main controller (please tell me your extending a MY_Controller.php and not just using CI_Controller.php), you'll want to read your 'admin' database and get all client information. You'll then want to generate a
$config
array for this client database and reload the database with the new$config
array:You'll then have a connection to the client database.
Note
If you'll need to connect to both databases back and forth, then you can connect to multiple databases as explained on this page: http://ellislab.com/codeigniter/user_guide/database/connecting.html