gpt4 book ai didi

php - CodeIgniter 其中值 IN (Field1,Field2)

转载 作者:行者123 更新时间:2023-11-29 05:35:13 25 4
gpt4 key购买 nike

我需要在我的授权脚本中设置查询,我想在 WHERE 子句中使用 '_MY_POST_VALUE' IN (Field1, Field2)

最终查询将是这样的:

SELECT * FROM 'myprefix_users' WHERE 'myemail@email.com' IN ('EMAIL','LOGIN') AND PASSWORD=SHA1('mypassword')

我试过这样做:

$this->db->where("'" . mysql_escape_string($_POST['login']) . "' IN (EMAIL,LOGIN)", NULL, FALSE);
$this->db->where("PASSWORD=SHA1('" . mysql_real_escape_string($_POST['password']) . "')");
$userdb = $this->db->get('users');

..但是 CodeIgniter 将前缀设置为我的登录/电子邮件值并发送错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''test@test.com' IN (EMAIL,LOGIN) AND PASSWORD=SHA1('123')' at line 3

SELECT * FROM (`myprefix_users`) WHERE myprefix_'test@test.com' IN (EMAIL,LOGIN) AND PASSWORD=SHA1('123')

我需要在表名中使用 db_prefix,但我的 WHERE 子句中不需要它,甚至 ->where() 中的第三个参数 (FALSE) 对我也不起作用:(

我该如何解决我的问题?有什么想法吗?

最佳答案

尝试使用 Codeigniter 的输入类。它将简化您的代码:

$login = $this->input->post('login', TRUE);
$password = $this->input->post('password', TRUE);
$this->db->where("'$login' IN ", "('EMAIL','LOGIN')", FALSE);
$this->db->where("PASSWORD", "SHA1('$password')", FALSE);
$userdb = $this->db->get('users');

关于php - CodeIgniter 其中值 IN (Field1,Field2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11347758/

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