Fatal error: Call to a member function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fixer
    Member
    • May 2001
    • 41

    Fatal error: Call to a member function

    it is a script which show the last 10 threads on wherever you want.
    it was working fine on vb3.0.7
    but now it does not.

    i fixed many errors but this one make me crazy

    this is what i ve got:

    Fatal error: Call to a member function query_first() on a non-object in c:\AppServ\www\vb350gold\ana\lastsetup.php on line 1903

    and this is the code of that line

    $childsets = $db->query_first("
    SELECT styleid, title, parentlist
    FROM " . TABLE_PREFIX . "style
    WHERE parentid = $styleid
    ");
  • Alan @ CIT
    Senior Member
    • Nov 2004
    • 107

    #2
    It means that $db isn't an object.

    If that code is within a function, make sure that $db has been globaled. Alternativly, check if $vbulletin has been globaled, and use $vbulletin->db->query_first(...

    Comment

    • gopherhockey
      Senior Member
      • Jul 2002
      • 123
      • 3.6.x

      #3
      Originally posted by Alan @ CIT
      It means that $db isn't an object.

      If that code is within a function, make sure that $db has been globaled. Alternativly, check if $vbulletin has been globaled, and use $vbulletin->db->query_first(...
      Could you explain the globaled thing?

      Here is a query I have that gives that same error:

      Code:
      $trails=$DB_site->query("SELECT * FROM conditiontrail ORDER BY trailid ASC");
      www.morcmtb.org

      Comment

      • Marco van Herwaarden
        Senior Member
        • Nov 2004
        • 6999
        • 3.8.x

        #4
        Globalizing is making the scope of a variable global, instead of only to the current function. To globalize a variable you can use the following syntax:
        PHP Code:
        global $myvar
        To answer the question in your first post, $db is probably pout of scope in the function where you are using it. Try using $vbulletin->db->query_first instead. If that still don't work, add a 'global $vbulletin;' on a line before this.

        In your second post your are using '$DB_site'. This is vB3.0.x syntax. This is in vB3.5 replaced by '$vbulletin->db'. Also 'query' is not used anymore (although it will still work), and should be replaced by either 'query_read' or 'query_write'.
        Want to take your board beyond the standard vBulletin features?
        Visit the official Member to Member support site for vBulletin Modifications: www.vbulletin.org

        Comment

        • fixer
          Member
          • May 2001
          • 41

          #5
          yup
          it is fixed now

          thanx

          Comment

          Related Topics

          Collapse

          Working...