[eluser]jshultz[/eluser]
I've got this weird issue happening in my code and I feel it just started. However, looking at my code's history I don't know how I introduced this bug?
This code here:
Code:
function get_all($siteid)
{
$query = $this->db->get_where('pages', array('siteid' => $siteid));
echo $this->db->last_query();
$row = $query->row_array();
$num = $query->num_rows();
if ($num < 1) {
return NULL;
} else {
return $query;
}
}
Will create the following query according to last_query:
Quote:SELECT `pageid`
FROM (`pages`)
WHERE `siteid` = '4556602514ec4a0885a5fa'array(1) {
["pageid"]=>
string(1) "1"
}
notice how it only selects "pageid" instead of all?
And this code:
Code:
function get_all($siteid)
{
$this->db->select('*')
->from('pages')
->where('siteid', $siteid)
->order_by('rank');
$query = $this->db->get();
echo $this->db->last_query();
$row = $query->row_array();
$num = $query->num_rows();
if ($num < 1) {
return NULL;
} else {
return $query;
}
}
Will produce the following query:
Quote:SELECT `pageid`, * FROM (`pages`) WHERE `siteid` = '4556602514ec4a0885a5fa' ORDER BY `rank`
And result in this error:
Quote:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM (`pages`) WHERE `siteid` = '4556602514ec4a0885a5fa' ORDER BY `rank`' at line 1
Notice how it tries to only select "pageid" and then puts a * after it?
How is this happening?