【问题标题】:passing value from database within a model从模型中的数据库传递值
【发布时间】:2018-08-15 17:12:33
【问题描述】:

作为登录的一部分,我使用的是在“用户”表中针对用户持有的密钥。我无法从数据库中获取密钥,然后使用它来解码密码。我从用户表中获取密钥,它没有将值分配给变量 $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) "正常运行时间:25131 线程:2 问题:380 慢查询:0 打开:28 刷新表:1 打开表:21 查询每秒平均: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 }

【问题讨论】:

  • 尝试使用print_rvar_dump$data。输出是什么?

标签: php database variables codeigniter-3


【解决方案1】:

替换

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

下面一行

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

更多信息请访问:

Documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-26
    • 2019-03-18
    • 1970-01-01
    • 2016-07-25
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多