By Martin Tobing → Tuesday, December 2, 2014
Untuk menampilkan query terakhir (bukan hasil query) yang telah dijalankan pada framework CodeIgniter, dengan menggunakan perintah $this->db->last_query().

Contoh Penggunaan :
File Model : (/application/models/my_model.php):

<?php if(! defined('BASEPATH'))exit('No direct script allowed access');

Class My_Model extends CI_Model{
function __construct(){
parent::__construct();
}
function get_last_query()
    {
        $query = $this->db->get('my_table', 2);
return $this->db->last_query(); // Return Last Query
    }
}
?>


File Controller : (/application/controllers/test.php):

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test extends CI_Controller {
public function index()
{
$this->load->model('my_model','my');
echo $this->my->get_last_query();
}
}
?>


Output : 

SELECT * FROM (`my_table`) LIMIT 2


Martin Tobing

I'm Martin Tobing. A full time web programmer. I enjoy to make website and web application in PHP.

No Comment to " Menampilkan Query Terakhir Menggunakan CodeIgniter "