Welcome Guest, Not a member yet? Register   Sign In
confusing mysql_num_rows() error
#1

[eluser]m9dfukc[/eluser]
hi,

I have some confusing error logs like:

ERROR - 2007-09-10 20:32:58 --> Severity: Warning --> mysql_num_rows(): supplied argument is not a valid MySQL result resource /var/www/html/andreas/xyz/system/database/drivers/mysql/mysql_result.php 37


but everyting seems working fine - any hints to fix that!? ... or should I just ignore that log???


best andreas
#2

[eluser]Michael Wales[/eluser]
The object that is calling this method is not a MySQL result resource - meaning the query didn't perform as you thought.

For example:
Code:
$query = $this->db->get('users');
echo $query->num_rows();

You would see the error if the users table did not exist (or if the framework could not connect to the database).

Look at where you are calling num_rows() function and ensure your queries are performing correctly. If they are, you'll see that log message go away.
#3

[eluser]ELRafael[/eluser]
Or if you want to count all rows from a table, uses

Code:
$this->db->count_all('put_the_name_of_table_here')
#4

[eluser]wojtekk[/eluser]
i had this error because of

Code:
$this->db->query("SET NAMES `utf8`");

in controller constructor
#5

[eluser]Unknown[/eluser]
Use $this->db->simple_query instead of $this->db->query with that "SET NAMES UTF8".
It worked for me - this annoying "Severity: Warning --> mysql_num_rows():" doesn't appear in log anymore Smile

(btw. setting Mysql to work with polish fonts is a nightmare Smile )
#6

[eluser]gr0uch0mars[/eluser]
I don't know why it returns no result, and num_rows() doesn't work (I think query is wrong, but I don't know where):
Code:
$this->db->select('issues.*, personnel.id AS artist_id, personnel.name AS artist');
$this->db->from('issues, personnel');
$this->db->where('issues.id', $issue_id);
$this->db->where('personnel.id', 'issues.artist_id');
$issue_q = $this->db->get();
return $issue_q;

(assuming $issue_id is a number)

If I construct the query directly, it works, but I'd rather use Active Record. Here I leave the direct query, if anyone knows how to solve the AR code, please tell me. I'd appreciate it!

Code:
$issue_q = $this->db->query("SELECT issues.*, personnel.id AS artist_id, personnel.name AS artist FROM issues, personnel WHERE issues.id = $issue_id AND personnel.id = issues.artist_id");

The fact that CI adds apostophres to the statement might be a problem? (I saw it with the Profiler)

Thanks!
#7

[eluser]gr0uch0mars[/eluser]
I changed this
Code:
$this->db->where('personnel.id', 'issues.artist_id');
for this
Code:
$this->db->where('personnel.id = issues.artist_id');

I don't know exactly why, but it works!!!
#8

[eluser]Dam1an[/eluser]
Try enabling the profiler see how the generated SQL differs
#9

[eluser]gr0uch0mars[/eluser]
OK, I see. Thanks.
#10

[eluser]faceh[/eluser]
[quote author="wojtekk" date="1191254327"]i had this error because of

Code:
$this->db->query("SET NAMES `utf8`");

in controller constructor[/quote]


You're a life saver... this was driving me mad! Thank you.




Theme © iAndrew 2016 - Forum software by © MyBB