这是我目前的代码:
public function index()
{
$tbl = 'm_trx';
$db = \Config\Database::connect();
$builder = $db->table($tbl);
$data = [];
$cols = "{$tbl}.*";
$builder->select($cols);
$data = $builder->get()->getResult();
$asd = [
'message' => $builder->getLastQuery(),
'data' => $data,
];
return $this->respond($asd);
}
但它返回错误"message": "Call to undefined method CodeIgniter\\Database\\MySQLi\\Builder::getLastQuery()",
如果我将$builder->getLastQuery()
更改为$builder->db->getLastQuery()
,它将返回此错误"message": "Cannot access protected property CodeIgniter\\Database\\MySQLi\\Builder::$db",
1条答案
按热度按时间svmlkihl1#
您只需要传递
$db
,而不需要传递$builder->db
试试这个