Fatal error: Call to a member function query() on a non-object |
[eluser]Creox[/eluser]
Hi Guys, Im tearing my hair out here as I cant do any database calls. Below are my database settings: Code: $active_group = 'default'; The database connects fine without any problems. I also have database autoloaded in autoload.php Code: $autoload['libraries'] = array('database'); But when I do a simple call like this: Code: public function _get(){ I get the following error: Quote:Fatal error: Call to a member function query() on a non-object in C:\wamp\www\greenModules\application\models\category_model.php on line 59 Please Help? What am i doing wrong? Thanks In Advance
[eluser]danmontgomery[/eluser]
You can't use magic getter and setter methods in the model, that's how CI connects the model to the controller. https://bitbucket.org/ellislab/codeignit....php#cl-47
[eluser]Creox[/eluser]
[quote author="noctrum" date="1308237172"]You can't use magic getter and setter methods in the model, that's how CI connects the model to the controller. https://bitbucket.org/ellislab/codeignit....php#cl-47[/quote] Thanks for the reply noctrum, I have chnaged _get() to getAll() and the problem still occurs. Im really stuck guys and could really do with your help. Thanks in Advance.
[eluser]John_Betong_002[/eluser]
Either: add this as a file and include it at the end of ./application/config/database.php or just append it to your ./application/config/database.php Code: // include 'database_DEBUG.php';
[eluser]Creox[/eluser]
Thanks, I know get the error Code: Invalid query: Whole query: Resource id #26 Your code above also checks a variable called $result at the end but that deos not appear anywhere else in your code. What is the problem with this? Please guys I have no idea!
[eluser]InsiteFX[/eluser]
You should always check to make sure you retrive data from a query! Code: public function get_all() InsiteFX
[eluser]John_Betong_002[/eluser]
[quote author="Creox" date="1308249769"]Thanks, I know get the error Code: Invalid query: Whole query: Resource id #26 Your code above also checks a variable called $result at the end but that deos not appear anywhere else in your code. What is the problem with this? Please guys I have no idea![/quote] Please accept my apologies for not testing the code. The script was copied and pasted. The variable $result should be $query. It looks like the connection to your database is OK and the problem is with the CI Active Record script.
[eluser]Creox[/eluser]
No problem. Sorry Guys I still gaent solved this. Im using 2.02 - The latest version. What do you recommend i should do?
[eluser]John_Betong_002[/eluser]
Have you tried using another table name? Also try http://localhost/phpmyadmin/index.php and check your database and tables. edit: Also try adding error checking and display errors: Code: public function _get() |
Welcome Guest, Not a member yet? Register Sign In |