In this tutorial, We will learn how to get the last executed query in PHP Codeigniter 3 using the last_query() function. You can print the last executed SQL query like select, create, update, delete query, etc.


Controller:

/**
 * Get All Data from this method.
 *
 * @return Response
*/
public function index()
{
    $data['data'] = $this->db->get("items")->result();
    $executedQuery = $this->db->last_query();
    print_r($executedQuery);
    exit;
}


output:

SELECT * FROM `items`