gpt4 book ai didi

php - Codeigniter 查询生成器,即使表中有数据,我也无法提取行并返回 null

转载 作者:行者123 更新时间:2023-11-29 11:57:24 26 4
gpt4 key购买 nike

这是我的代码,有错误

Fatal error: Call to undefined method CI_DB_mysqli_driver::row()

$query = $this->db->select( 'a.*, b.feild1 as feild1, b.feild2 as feild2' )
->from('game as a')
->join('transaction as b', 'a.transactionID = b.transactionID', 'left')
->where('a.clientID', $clientID)
->order_by('a.transactionID', 'DESC')
->limit(1);
->row();
$row = $query->row();

然后我使用了 get();并编码为 json 格式,我的所有响应均为 null

即使我的表中有数据,所有值仍为空。查询生成器生成此

SELECT a.*,b.field as 'feild', b.field2 as 'field2'
FROM (game as a)
LEFT JOIN transaction as b ON a.transactionID = b.transactionID
WHERE a.clientID = 1234
ORDER BY a.transactionID DESC
LIMIT 1

最佳答案

删除了 ->row(); 添加了 get

尝试这样的事情

public function some_function_name($clientID) {
$this->db->select('a.*, b.feild1 as feild1, b.feild2 as feild2' );
$this->db->from($this->db->dbprefix . 'game as a');
$this->db->join($this->db->dbprefix . 'transaction as b', 'a.transactionID = b.transactionID', 'left');
$this->db->where('a.clientID', $clientID);
$this->db->order_by('a.transactionID', 'DESC');
$this->db->limit(1);
$query = $this->db->get();
return $query->row_array();
}

或者

public function some_function_name($clientID) {
$this->db->select('a.*, b.feild1 as feild1, b.feild2 as feild2' );
$this->db->from($this->db->dbprefix . 'game a');
$this->db->join($this->db->dbprefix . 'transaction b', 'a.transactionID = b.transactionID', 'left');
$this->db->where('a.clientID', $clientID);
$this->db->order_by('a.transactionID', 'DESC');
$this->db->limit(1);
$query = $this->db->get();
return $query->row_array();
}

关于php - Codeigniter 查询生成器,即使表中有数据,我也无法提取行并返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32984523/

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