在模型中传递来自数据库的值

时间:2018-03-07 14:46:07

标签: php database variables codeigniter-3

作为登录的一部分,我正在使用“用户”表中针对用户的密钥。我无法从数据库中获取密钥,然后使用它来解码密码。我从用户表中获取密钥,并不知道将值赋给变量$ data,认为从查询返回的值是一个数组我尝试将$ data变量引用为$ data [0]但是没有区别。

 public function checklogin($Email,$Pass)
    {
        $data = $this->db->query(select Key from users where User = $Email);

        $Password = $this->encrypt->decode($Pass,$data);

        $this->db->select('User','Pwd','Level');
        $this->db->from('users');
        $this->db->where('User', $Email);
        $this->db->where('Pwd', $Password);
        $this->db->where('Active','Y');

        $query = $this->db->get();      
    }

Var转储返回: object(CI_DB_mysqli_result)#25(8){[“conn_id”] => object(mysqli)#15(19){[“affected_rows”] => int(1)[“client_info”] => string(79)“mysqlnd 5.0.11-dev - 20120503 - $ Id:76b08b24596e12d4553bd41fc93cccd5bac2fe7a $”[“client_version”] => int(50011)[“connect_errno”] => int(0)[“connect_error”] => NULL [“errno”] => int(0)[“error”] => string(0)“”[“error_list”] => array(0){} [“field_count”] => int(1)[“host_info”] => string(20)“localhost via TCP / IP”[“info”] => NULL [“insert_id”] => int(0)[“server_info”] => string(21)“5.5.5-10.1.25-MariaDB”[“server_version”] => int(50505)[“stat”] => string(134)“Uptime:25131 Threads:2 Questions:380 Slow queries:0 Opens:28 Flush tables:1 Open tables:21 Queries per second avg:0.015”[“sqlstate”] => string(5)“00000”[“protocol_version”] => int(10)[“thread_id”] => int(89)[“warning_count”] => int(0)} [“result_id”] => object(mysqli_result)#24(5){[“current_field”] => int(0)[“field_count”] => int(1)[“lengths”] => NULL [“num_rows”] => int(1)[“type”] => int(0)} [“result_array”] => array(0){} [“result_object”] => array(0){} [“custom_result_object”] => array(0){} [“current_row”] => int(0)[“num_rows”] => NULL [“row_data”] => NULL}

1 个答案:

答案 0 :(得分:1)

替换

$query = $this->db->get(); 

使用以下行

$query = $this->db->get()->result_array();

更多信息请访问:

Documentation