Call to a member function num_rows() on a non-object |
[eluser]trumnation[/eluser]
Hi, I'm having troubles with the num_rows() function. I keep getting the following error: Fatal error: Call to a member function num_rows() on a non-object in E:\Server 2\Root\application\models\userdatamodel.php on line 1296 here is the code I am using: Code: function compare($friendId, $userId = '') Can anyone tell me why I'm getting this error? Thanks! Derek
[eluser]trumnation[/eluser]
No, that doesn't work. It gives me an empty property error. Is there anything else that could be causing this problem?
[eluser]alboyd[/eluser]
I'd start by doing a echo var_dump($Query) and see what it looks like. It's presumably empty - but that's odd. Try writing the query out without using activerecord and then executing it. Basically isolating what could be the cause.
[eluser]trumnation[/eluser]
You would be correct about that - it is empty. I did try writing the query out and not using activerecord - I even just tried to select the entire table and it still didn't work... here is the code I used: Code: $sql1 = "SELECT * FROM `friends_list`"; This is such a simple task.. just grab data from a table and return true if there was actually anything in the table..... but it doesn't work. Is there something in the codeigniter core that causes this, or am I just missing something really simple?
[eluser]InsiteFX[/eluser]
Code: var $CI; // The CI object I had the same problem designing the new menu system for the Fresh CMS. I had autoloaded the databse and still gave me errors on num_rows. You can also do it like this: Code: $query = $this->CI->db->query("SELECT * FROM `friends_list`"); Enjoy InsiteFX
[eluser]alboyd[/eluser]
Code: $sql1 = "SELECT * FROM `friends_list`"; Try just "SELECT * FROM friends_list" As long as you are doing this in a model I don't think why you would need to get a copy of CI ? EDIT: btw - do you have error logging on? Because I think you are not seeing an error - how else could it not return either true or false to num_rows()? I'd say the query itself is failing...
[eluser]trumnation[/eluser]
@InsiteFX - I tried what you suggested, however on the var $CI; it gives me an unexpected T_VAR error.. I am using this function in a model. Does this make any difference rather than using a controller? @alboyd - No matter whether I have the quotes around friends_list or not, it still doesn't work. Good idea on turning on error logging. It did produce an error, although I am at a complete loss on how to fix it, wouldn't this be a problem with the database driver? Code: Severity: Warning --> mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: Unable to save result set E:\Server 2\Root\CodeIgniterCore\database\drivers\mysql\mysql_driver.php 125
[eluser]Zorancho[/eluser]
Try $this->db->num_rows() instead of $query->num_rows()
[eluser]trumnation[/eluser]
Still haven't been able to find what is causing this error and how to fix it. Is there anything else i'm missing? |
Welcome Guest, Not a member yet? Register Sign In |