gpt4 book ai didi

database - Codeigniter 使用数据库类插入 MySQL 函数

转载 作者:搜寻专家 更新时间:2023-10-30 19:46:31 24 4
gpt4 key购买 nike

我得到了数据,这些数据将使用 CI 的数据库类保存到我的数据库中:

$data = array(
'login' => $this->input->post('login', TRUE),
'password' => $this->input->post('password', TRUE),
'email' => $this->input->post('email', TRUE)
);

return $this->db->insert('account', $data);

现在我需要使用 MySQL 函数 PASSWORD() 来获取 password post hash。

我试过这种方式:

'password' => "PASSWORD(". $this->input->post('password', TRUE) . ");

但 CI 的数据库类将其转换为以下字符串:

INSERT INTO `accounts` [..] 'PASSWORD("mypassword")'

如您所见,它不会工作,因为它将在 ' 之间保存整个字符串。

是否有任何解决方案,或者我必须使用 $this->db->query

最佳答案

您可以使用 set() 方法来设置您的 INSERT 值,然后传递第三个参数 (FALSE) 以防止 CodeIgniter 转义 PASSWORD。像这样:

$this->db->set('login', $this->input->post('login', TRUE));
$this->db->set('password', 'PASSWORD("'.$this->input->post('password', TRUE).'")', FALSE);
$this->db->set('email', $this->input->post('email', TRUE));

return $this->db->insert('account');

关于database - Codeigniter 使用数据库类插入 MySQL 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9232451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com