doudui9516 2013-09-28 15:32
浏览 12
已采纳

Cakephp在登录基础上选择数据库

I would like to know if there is a way to do a multiple database system

For example I have many clients registered to my system and I want when the y login to select its databasse because I want to divide every client with an own database. Is this correct? Because I want to separate information of each client. Well, I think that i have to make multipl configuration into the database file of cakephp but I don't know hot to do this: When the client make the lgin (use default database), when they login I want to take a variable inside a table that contain the name of its database and after make it the active database.

is this possible? I can't declare foreach client the database configuration.

Can anyone help me in this?

Thanks

This is my actual default database in database.php

public $default = array (
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'login',
        'password' => 'password_',
        'database' => 'default_db',
        'prefix' => ''
    );

I would like to separate database because I want to create some pages where every client can edit filed of some tables because for example: if they want to add to table project field notes, they can, anotoher client don't want this filed but many and many others. I would like to create a system to get the possibility to edit some table.
For that there are two solution:

- separate database at login in base of login
- use a unique database ad every time a user registered I create automatically its table for example there isn't table project but project_{user_id} for example, every user can have its table.

Which method is better?

Thanks

  • 写回答

1条回答 默认 最新

  • dongmi1872 2013-09-29 21:15
    关注

    I want to divide every client with an own database. Is this correct? I think it's not a good idea to realize this task using CakePHP, but it is possible, take a look to CakePHP DataSources. In simple way your solution should be like this:

    1. Setup main database, containing some application-specified data.
    2. Authorize user, using MySQL built-in technologies.
    3. Use another DataSource with authorized user access-data.

    You must take care of granting privileges.

    Which method is better?

    It depends of user amount. If it is two or three, there is no difference between your methods. But if it is 100 or 1000 it will be hard to manage your tables. Remember Ockhman's words: entities must not be multiplied beyond necessity. Use MySQL-way, databases must store tables, users can access databases. Don't break this rule.

    Also take a look at PHPMyAdmin, maybe it will be better to change it for your needs, it is licensed under GNU GPL2 license.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳