vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   $db->query_read inside a function? (https://vborg.vbsupport.ru/showthread.php?t=144421)

cashpath 04-09-2007 06:48 PM

$db->query_read inside a function?
 
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

Code:

   
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
PHP Code:

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.


All times are GMT. The time now is 03:07 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00900 seconds
  • Memory Usage 1,716KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete