Kieran-R Posted October 24, 2010 Share Posted October 24, 2010 Hey guys. Well I have been encountering a problem with one of my scripts, and I have no idea what is causing it... 2. include "config.php"; 3. $wq=$db->query("SELECT * FROM users WHERE job > 0"); The error is: Fatal error: Call to a member function query() on a non-object in ..... on line 3 If someone could point out too me where I am going wrong with this code then that would be great! Thanks. Quote Link to comment Share on other sites More sharing options...
Dominion Posted October 24, 2010 Share Posted October 24, 2010 to use $db->query you need to include the class file not just the config one Quote Link to comment Share on other sites More sharing options...
corruptcity || skalman Posted October 24, 2010 Share Posted October 24, 2010 you need to include globals.php Quote Link to comment Share on other sites More sharing options...
Kieran-R Posted October 24, 2010 Author Share Posted October 24, 2010 OK ill try that now :) Thanks for the help guys. Quote Link to comment Share on other sites More sharing options...
Kieran-R Posted October 24, 2010 Author Share Posted October 24, 2010 Yep its worked :) Ive never accualy thought of $db-> that way lol... Cheers Quote Link to comment Share on other sites More sharing options...
corruptcity || skalman Posted October 24, 2010 Share Posted October 24, 2010 nps Quote Link to comment Share on other sites More sharing options...
Dominion Posted October 24, 2010 Share Posted October 24, 2010 you need to include globals.php globals also puts the header and the querys that take everything out of the user table and so on. If it's a cron or something the user will never need to see then no you do not need globals.php to use $db-> just the class file. of course the class file gets included at the top of globals anyway so it would still work, just not needed all the time. Quote Link to comment Share on other sites More sharing options...
Joshua Posted October 25, 2010 Share Posted October 25, 2010 You couldnt just use the class file as the config is run seperately for actually connecting to the database >< You would need to add all the connection queries etc then actually define db as new Quote Link to comment Share on other sites More sharing options...
Dominion Posted October 25, 2010 Share Posted October 25, 2010 true, however if you look in the 1st post config.php is already being included and connecting to the database would have been a given. it's still better then including the whole globals file if you don't need to. Quote Link to comment Share on other sites More sharing options...
Kieran-R Posted October 25, 2010 Author Share Posted October 25, 2010 I've just been using globals.php but I know that is loading loads of unnecicery data. I know mcc v.2 is ussualy $db->, But wouldn't mysql_ just work the same if I'm only including the config file? Quote Link to comment Share on other sites More sharing options...
Dominion Posted October 25, 2010 Share Posted October 25, 2010 no config.php does not connect you to the database you could just use mysql_connect() at the top of the file and mysql_query() that way? may i ask what the file is doing? if it's public just keep globals Quote Link to comment Share on other sites More sharing options...
Kieran-R Posted October 25, 2010 Author Share Posted October 25, 2010 Its fixed anyway mate... Its actually a cron file, but its running fine even when including globals.php... Thanks for the help guys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.