我试图在具有不同数据库表的多用户网站上创建注册表。
例如,当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()
];
您可以通过在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