Welcome Guest, Not a member yet? Register   Sign In
a question about active record
#1

[eluser]kodkanyon[/eluser]
Hello,

I don't have a problem when i use id IN ('.$id.') in a SQL sentence but whenever i use (?) there is a problem.

It works::

models:
function query($sql,$array){
$query = $this->db->query($sql,$array);
return $query->result($array);
}

controllers:
$this->MGenel->query('SELECT * FROM bloklar WHERE dil = ? AND id IN ('.$id.') ORDER BY agirlik', $this->session->userdata('dil'));

output with last_query:
SELECT adi,dosya_yolu,icerik,agirlik FROM bloklar WHERE gosterim="aktif" AND dil = 'tr' AND id IN (1,2) ORDER BY agirlik

When it doesn't work:

controllers:
$this->MGenel->query('SELECT adi,dosya_yolu,icerik,agirlik FROM bloklar WHERE gosterim="aktif" AND dil = ? AND id IN (?) ORDER BY agirlik', $id, $this->session->userdata('dil'));

Error Msg:
Fatal error: Call to a member function result() on a non-object in

Thanks for your help.
#2

[eluser]Aken[/eluser]
Code:
controllers:
$this->MGenel->query(‘SELECT * FROM bloklar WHERE dil = ? AND id IN (’.$id.’) ORDER BY agirlik’, $this->session->userdata(‘dil’));

output with last_query:
SELECT adi,dosya_yolu,icerik,agirlik FROM bloklar WHERE gosterim=“aktif” AND dil = ‘tr’ AND id IN (1,2) ORDER BY agirlik

These are not the same queries. You should post your code in full, using the [ code ] tags.
#3

[eluser]PhilTem[/eluser]
Getting

Code:
Fatal error: Call to a member function result() on a non-object in

as error message usually means there were no rows found matching your query thus it cannot return results. That's why you should always be using

Code:
if ( $query->num_rows() > 0 ) {
  return $query->result();
}

return array();

i.e. check for empty queries before returning a result object/array.

But @Aken is correct: Your queries are not the same. Please post more of your code using the [ code ] tags (without the whitespaces of course)
#4

[eluser]Aken[/eluser]
[quote author="PhilTem" date="1354883957"]Getting

Code:
Fatal error: Call to a member function result() on a non-object in

as error message usually means there were no rows found matching your query thus it cannot return results. That's why you should always be using

Code:
if ( $query->num_rows() > 0 ) {
  return $query->result();
}

return array();

i.e. check for empty queries before returning a result object/array.[/quote]

This error happens when the query fails, not when zero rows are returned. If a query is successful and no rows are returned, methods for returning results will simply be empty. Using the code above will help hide any errors like that, but may make debugging your code more difficult (since you won't get errors, lol).




Theme © iAndrew 2016 - Forum software by © MyBB