0

Hi I need to cache only one query in my CI app. I dont understand what to do now. For example I have this in my config/database.php

$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = APPPATH . 'cache';

And this is my model:

public function get_languages() {
        $this->db->cache_on();
        $this->db->save_queries = TRUE;
        log_message("error", "getLanguages!!!!!!!!!!!!!");
        $this->db->from('tbl_language'); 
        $result = $this->db->get();
        $results = $result->result_array();
        log_message("error", $this->db->last_query());
        return $results;
}

I always see the query is executed in DB. Some help please! What is wrong?

1 Answer 1

2

below code worked me!

public function get_languages() {
        $this->db->cache_on();
        $this->db->save_queries = TRUE;
        log_message("error", "getLanguages!!!!!!!!!!!!!");
        $this->db->from('tbl_language'); 
        $result = $this->db->get();
        $results = $result->result_array();
        var_dump($results);//print for checking
        $count = $result->num_rows();
        log_message("error", $this->db->last_query());
        if($count>0)
        {
            foreach($results as $list)
            {
                echo $list['id'];
            }           
        }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.