Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flush or reset codeigniter active records without execute after build?

Actually i saw some suggestions in stackoverflow itself but didnt get the exact solution for this issue, Please dont think this is a duplicate.

Am using memcache for my codeigniter site and active records to build query. Am using

    this->db->return_query_string();

to get the query from active records before executing .Now i want to flush the active records with out executing the same query.

also from various references

     $this->db->start_cache();
     $this->db->stop_cache();
     $this->db->flush_cache()

may do the job is this is the exact result? if so how can i get the cached query with out execute

like image 213
seetharaman Avatar asked Feb 17 '23 02:02

seetharaman


2 Answers

You can use these two functions for your requirements

public function _compile_select($select_override = FALSE)
public function _reset_select()

To use them you will have to remove public or private keywords.
Go to system/database/DB_active_rec.php Remove public or protected keyword from these functions

Example usage

$this->db->select('trans_id');
$this->db->from('myTable');
$this->db->where('code','B');
$subQuery = $this->db->_compile_select();

$this->db->_reset_select();

$subQuery contains the query string and _reset_select resets the active record so you can write a new query.

like image 180
Muhammad Raheel Avatar answered May 26 '23 02:05

Muhammad Raheel


Starting from CodeIgniter 3.x, you can do:

$subQuery = $this->db
    ->select('trans_id')
    ->where('code', 'B')
    ->get_compiled_select('myTable');
like image 30
Gras Double Avatar answered May 26 '23 03:05

Gras Double