如何使用不同的数据库表创建注册表格式的点火器

问题描述 投票:0回答:1

我试图在具有不同数据库表的多用户网站上创建注册表。

例如,当user1注册时,数据将输入到表“ user1”中,当user2注册时,在表“ user2”中输入。

我只能在同一表中输入user1和user2。这是我的代码,使用role_id

$data = [
            'name' => htmlspecialchars($this->input->post('nama', true)),
            'username' => htmlspecialchars($this->input->post('username', true)),
            'photo' => 'default.jpg',
            'password' => password_hash($this->input->post('password1'), PASSWORD_DEFAULT),
            'role_id' => 2,
            'is_active' => 1,
            'is_date' => time()
        ];
codeigniter user-roles multi-user
1个回答
0
投票

您可以通过在role_id上应用条件来执行此操作,但这仅在用户数量众多的情况下才可以执行。如果有很多用户,并且您要为每个用户创建一个单独的表,请尝试Database Forge Class(不良做法)

我已经为您的问题写了一个可能的解决方案,在必要时会提及您的评论。看看是否对您有帮助。

Controller

Database Forge Class

Xyz_model

$data = [
            'name' => htmlspecialchars($this->input->post('nama', true)),
            'username' => htmlspecialchars($this->input->post('username', true)),
            'photo' => 'default.jpg',
            'password' => password_hash($this->input->post('password1'), PASSWORD_DEFAULT),
            'role_id' => 2,
            'is_active' => 1,
            'is_date' => time()
        ];

$this->xyz_model->xyz_function($data); // load xyz_model and call xyz_function with $data parameters
© www.soinside.com 2019 - 2024. All rights reserved.