我如何从Codeigniter中的conn_id获取属性值?

时间:2016-07-21 06:24:14

标签: php codeigniter

我已经使用var_dup()检查Codeigniter查询执行或查询后查询任何数据,然后我得到如下结果,但所有这些只包含空值和 我怎样才能从这些财产中获得真正的价值?

示例,如果我想从 warning_count 获取价值。

我希望从Object下面获取值,因为我从Model中转储它。

object(CI_DB_mysqli_result)[20]
  public 'conn_id' => 
    object(mysqli)[17]
      public 'affected_rows' => null
      public 'client_info' => null
      public 'client_version' => null
      public 'connect_errno' => null
      public 'connect_error' => null
      public 'errno' => null
      public 'error' => null
      public 'error_list' => null
      public 'field_count' => null
      public 'host_info' => null
      public 'info' => null
      public 'insert_id' => null
      public 'server_info' => null
      public 'server_version' => null
      public 'stat' => null
      public 'sqlstate' => null
      public 'protocol_version' => null
      public 'thread_id' => null
      public 'warning_count' => null
  public 'result_id' => 
    object(mysqli_result)[26]
      public 'current_field' => null
      public 'field_count' => null
      public 'lengths' => null
      public 'num_rows' => null
      public 'type' => null
  public 'result_array' => 
    array (size=0)
      empty
  public 'result_object' => 
    array (size=0)
      empty
  public 'custom_result_object' => 
    array (size=0)
      empty
  public 'current_row' => int 0
  public 'num_rows' => int 11
  public 'row_data' => null


 Qquery result

array (size=11)
  0 => 
    object(stdClass)[27]
      public 'p_id' => string '3' (length=1)
      public 'fk_c_id' => string '1' (length=1)
      public 'fk_group_id' => string '1' (length=1)
      public 'fk_user_id' => null
      public 'manufacturer_id' => null
      public 'stock_status_id' => string '0' (length=1)
      public 'model' => string '1' (length=1)
      public 'sku' => string '' (length=0)
      public 'p_name' => string 'asset/img/main/9.jpg' (length=20)
      public 'ean' => string '' (length=0)
      public 'jan' => string '' (length=0)
      public 'isbn' => string '' (length=0)
      public 'mpn' => string '' (length=0)
      public 'location' => string '' (length=0)
      public 'quantity' => string '0' (length=1)
      public 'image' => string 'asset/img/main/9.jpg' (length=20)
      public 'shipping' => string '1' (length=1)
      public 'price' => string '1.0000' (length=6)
      public 'points' => string '0' (length=1)
      public 'tax_class_id' => string '0' (length=1)
      public 'date_available' => string '0000-00-00' (length=10)
      public 'weight' => string '0.00000000' (length=10)
      public 'weight_class_id' => string '0' (length=1)
      public 'length' => string '0.00000000' (length=10)
      public 'width' => string '0.00000000' (length=10)
      public 'height' => string '0.00000000' (length=10)
      public 'length_class_id' => string '0' (length=1)
      public 'subtract' => string '1' (length=1)
      public 'minimum' => string '1' (length=1)
      public 'sort_order' => string '0' (length=1)
      public 'status' => string '1' (length=1)
      public 'date_added' => string '0000-00-00 00:00:00' (length=19)
      public 'date_modified' => string '0000-00-00 00:00:00' (length=19)
      public 'viewed' => string '0' (length=1)
  1 => 

模型

public function selects($data = null, $table = null, $where = null, $order = null, $limit = null)
{
    $data = $this->get_data($data, $table, $where, $order, $limit);
    var_dump($data);
    if (!$data) {
        return ['result' => 'There are no data available for you, Sorry!!!'];
    }
    return $data;
}

private function get_data($data = null, $table = null, $where = null, $order = null, $limit = null)
{
    if ($this->db->table_exists($table))
    {
        return ['result'=>'This table '.'"'.$table.'"'.' is not existing'];
    }
    if (!empty($data)) {
        $this->db->select($data);
    }
    if (!empty($where)) {
        $this->db->where($where);
    }
    if (!empty($order)) {
        $this->db->order_by($order);
    }
    if (!empty($limit)) {
        $this->db->limit($limit);
    }
    $this->db->from($table);
    $this->_data = $this->db->get();
    if ($this->-data->num_rows() <=0) {
        return false;
    }
    return $this->_data;
}

在控制器中调用

$this->Products_model->selects('*', 'productsa')->result();

1 个答案:

答案 0 :(得分:0)

试试这个

var_dump($data->conn_id->warning_count);

实际上这些属性值都是有条件的。像insert_id一样,只有在插入DB时才显示最后插入的ID。同样的警告&amp;错误属性。没有错误&amp;在这个查询中出现警告,这就是为什么它显示NULL值。