PDA

View Full Version : $db->query_read inside a function?


cashpath
04-09-2007, 06:48 PM
I have a funtions include file with $db->query_read in the functions but when the page is called I get

Fatal error: Call to a member function query_read() on a non-object in /home/madden/public_html/forum/league_functions/functions_inc.php on line 191


190: $sql="select t.team as teamname, s.*,((s.win+(s.tie/2))/(s.win+s.loss+s.tie)) as Percent from $table s INNER JOIN $table_2 t ON t.team=s.team WHERE s.week='".$week."' and s.year='".$year."' AND t.conf='".$conf."' AND t.division='".$div."' ORDER by Percent DESC";

191: $teamstanding=$db->query_read($sql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());;

192: while($tresult=mysql_fetch_object($teamstanding)){


Do I just have to use regular mysql_queries in the functions?

Adrian Schneider
04-09-2007, 07:16 PM
add global $db; to the top of your function.

cashpath
04-09-2007, 07:31 PM
Thank you!

Dismounted
04-10-2007, 04:22 AM
Or you could just use $vbulletin->db->

cashpath
04-10-2007, 11:33 AM
Is one way better than the other?

Dismounted
04-10-2007, 11:37 AM
They reference to the same thing, it's just that $vbulletin-> doesn't require you to globalize $db, thus saving you a line of code :).

cashpath
04-10-2007, 01:26 PM
Ah.. makes sense, thanks.