Fatal error: Call to a member function query() on a non-object - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Fatal error: Call to a member function query() on a non-object (/showthread.php?tid=42697) Pages:
1
2
|
Fatal error: Call to a member function query() on a non-object - El Forum - 06-16-2011 [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 Fatal error: Call to a member function query() on a non-object - El Forum - 06-16-2011 [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/codeigniter-reactor/src/6b1e35f45ca5/system/core/Model.php#cl-47 Fatal error: Call to a member function query() on a non-object - El Forum - 06-16-2011 [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/codeigniter-reactor/src/6b1e35f45ca5/system/core/Model.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. Fatal error: Call to a member function query() on a non-object - El Forum - 06-16-2011 [eluser]Creox[/eluser] Anyone? Fatal error: Call to a member function query() on a non-object - El Forum - 06-16-2011 [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'; Fatal error: Call to a member function query() on a non-object - El Forum - 06-16-2011 [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! Fatal error: Call to a member function query() on a non-object - El Forum - 06-16-2011 [eluser]InsiteFX[/eluser] You should always check to make sure you retrive data from a query! Code: public function get_all() InsiteFX Fatal error: Call to a member function query() on a non-object - El Forum - 06-16-2011 [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. Fatal error: Call to a member function query() on a non-object - El Forum - 06-16-2011 [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? Fatal error: Call to a member function query() on a non-object - El Forum - 06-16-2011 [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() |