Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在CodeIgniter中编写用于数据库查询的复合语句_Php_Database_Codeigniter - Fatal编程技术网

Php 如何在CodeIgniter中编写用于数据库查询的复合语句

Php 如何在CodeIgniter中编写用于数据库查询的复合语句,php,database,codeigniter,Php,Database,Codeigniter,为了设计密码用户名身份验证,我尝试从表(成员资格)中检索“salt”,并将其附加到密码中。然后用SHA256对组合进行加密。但是当我像下面那样编写validate()函数时,出现了一个错误 严重程度:4096 消息:无法将类CI\u DB\u mysql\u驱动程序的对象转换为 串 代码: 如何解决这个问题?我正在使用codeigniter 2.1.2。非常感谢 您需要创建两个独立的查询: public function validate(){ $this->db->sel

为了设计密码用户名身份验证,我尝试从表(成员资格)中检索“salt”,并将其附加到密码中。然后用SHA256对组合进行加密。但是当我像下面那样编写validate()函数时,出现了一个错误

严重程度:4096

消息:无法将类CI\u DB\u mysql\u驱动程序的对象转换为 串

代码:


如何解决这个问题?我正在使用codeigniter 2.1.2。非常感谢

您需要创建两个独立的查询:

public function validate(){

    $this->db->select('salt');
    $this->db->where('username', $this->input->post('username', TRUE));
    $salt = (string) $this->db->get('membership')->row()->salt;

    $this->db->where('password', 
                    hash('sha256', $this->input->post('password', TRUE). $salt));
    $query=$this->db->get('membership'); 

    if($query->num_rows()==1) { 
         return TRUE; 
    }
    return FALSE;
}

这不能用MySQL的散列来完成吗?i、 e.
$this->db->where('Password','SHA2(concat('.$this->db->escape('this->db->post('Password',true)),'salt),256',空)
public function validate(){

    $this->db->select('salt');
    $this->db->where('username', $this->input->post('username', TRUE));
    $salt = (string) $this->db->get('membership')->row()->salt;

    $this->db->where('password', 
                    hash('sha256', $this->input->post('password', TRUE). $salt));
    $query=$this->db->get('membership'); 

    if($query->num_rows()==1) { 
         return TRUE; 
    }
    return FALSE;
}