Welcome Guest, Not a member yet? Register   Sign In
Issue with Custom DB Result Object with DB Cache Enabled
#1

Hi,

I am using the CI Query Builder to execute a simple SQL query as follows:

PHP Code:
$query $this->db->query($sql, array($binds));
        
        
if($query->num_rows() > 0)
        {
            return $query->result('my_class_entity');
        

The above works without any issues and returns the expected array of result objects of 'My_class_entity'.

However, as soon as I enable DB query caching I am unable to generate a result with a custom result object. For example using the following code:
PHP Code:
$this->db->cache_on();
        
$query $this->db->query($sql, array($binds)); 
        
        if(
$query->num_rows() > 0)
        {
            return 
$query->result('my_class_entity');
        } 

The result of $query->result('my_class_entity') in this case is simply an empty array. However if I return $query->result() or explicitly $query->result_array() or $query->result_object() the expected data is returned as either an array or array of StdClass objects.

As far as I can tell there is no caching issue itself as the cache file is correctly generated, no caching related errors appear in the log and returning a generic $query->result() works fine. I've attempted modifying the query component to: $query = $this->db->query($sql, array($binds), true); although this doesn't seem to have any effect and the CI documentation for 3.X is not clear on what this truly does.

Is this a limitation in CI that prevents a custom object result being returned with query caching, or am I missing something here?

Thanks.
Reply
#2

CodeIgniter 4 User Guide - Custom Result Objects
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB