Welcome Guest, Not a member yet? Register   Sign In
Any idea why CI gives different SQL results than running the query through Navicat?
#1

[eluser]elverion[/eluser]
This has been bugging me for a few hours now. I figured I must have just been doing the query wrong, but upon trying it through Navicat's query system, I noticed I was getting the correct results. Basically, when I run this through CI, I get 0 results returned.

I have this code:
Code:
$this->read_db->select('objects.*');
$this->read_db->join('object_stats', 'object_stats.object_id = objects.id');
$this->read_db->where('object_stats.user_id', $user_id);
$this->read_db->where('object_stats.completed', 'yes');
$this->read_db->group_by('objects.id');
$query = $this->read_db->get('objects');

$last_query = $this->read_db->last_query();

log_message('debug', 'QUERY:' . $last_query);
$res = $query->result();
log_message('debug', 'COUNT:' . count($res));

The log shows:
Code:
DEBUG - 2011-11-21 05:27:24 --> QUERY:SELECT `objects`.*
FROM (`objects`)
JOIN `object_stats` ON `object_stats`.`object_id` = `objects`.`id`
WHERE `object_stats`.`user_id` = '1'
AND `object_stats`.`completed` = 'yes'
GROUP BY `objects`.`id`
DEBUG - 2011-11-21 05:27:24 --> COUNT:0

As you can see, no results are returned. The log is set to show everything, so no error has occurred. If I straight copy and paste that query into Navicat's query interface to query the SQL server directly, it returns 1 result (which is correct). Any ideas?




Theme © iAndrew 2016 - Forum software by © MyBB