Search code examples
cakephp-2.x

Cannot retrieve data from find query


In my Event model, I have the following function to retrieve all the events with status = 1 with a 12 limit and order according to event created DESC:

public function latestEvents() {
    $this->Behaviors->load('Containable');
    $result = $this->find('all' ,array('recursive' => -1, 'conditions'=> array('Event.status' => 1), 'limit' => 12, 'order' => array('Event.created DESC')));
    debug($result); die();
    return $result;
}

This function is not returning any data. When I change my limit to 6 and debug it returns six records but when I change my limit to more than 6 it returns (empty) this : enter image description here

I even checked in my database by doing this query :

SELECT * FROM `events` WHERE `status` = 1 ORDER BY `created` DESC LIMIT 12

and this returns the desired data that I want. I even tried :

$result = $this->query('SELECT * FROM `events` WHERE `status` = 1 ORDER BY `created` DESC LIMIT 12');

but the same thing is happening with the limit (6 returns the data but more than 6 does not).


Solution

  • I found out that the data I was trying to debug had special characters and I had to include 'encoding' => 'utf8' in my database.php and worked like a charm. This post helped me.