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

标签 php mysql codeigniter

这是我的代码,有错误

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/

相关文章:

php - 如何使用 codeigniter 在数据库中提交多行表格数据?

php - 将特殊字符插入数据库

mysql - 通过在同一表中选择具有另一个条件的行来更新具有 where 条件的行

php - 如何从 MySQL 数据库中提取某个项目的类别和标签?

php - 如何(正确)使用具有依赖关系的表单请求+策略+资源路由?

php - 从mysql数据库中的特定用户中选择数据到PHP

mysql - MySQL 中的嵌套 CASE 语句

php - 如何使用查询生成器将 mysql 查询转换为 codeigniter?

php - 使用 PHPExcel 和 AJAX 制作 Excel 文件

php - 如何在 Codeigniter 中将 SQL 结果字符串转换为数组?