Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Jan 2008
    Posts
    49
    Plugin Contributions
    0

    Default Problem with Function Scope. $db->Execute works inline, but not in a function?!

    Hey guys,

    I've written a function called add_category. It works off the code from categories from php. I'm having a devil of a time with scope though. When I run the code inline, it runs fine. However, when I throw function add_category( ) { } around the code, it throws:


    Fatal error: Call to a member function Execute() on a non-object in /Applications/MAMP/htdocs/shop/admin/cat.php on line 105

    I know this is a weird global scope issue or something. At the top of my file I have...

    <?php
    require_once('includes/application_top.php');

    global $db;


    Anyhow, What is the secret here? How do I work around this quirk. I'll be gosh durned and dipped in cherries before I use a goto.

    Thanks,

    Josh

  2. #2
    Join Date
    Apr 2007
    Location
    Herts. UK
    Posts
    890
    Plugin Contributions
    4

    Default Re: Problem with Function Scope. $db->Execute works inline, but not in a function?!

    Quote Originally Posted by enigmabomb View Post

    I know this is a weird global scope issue or something. At the top of my file I have...

    <?php
    require_once('includes/application_top.php');

    global $db;
    The global $db; needs to be inside the function instead of outside of it so that you have something like...
    PHP Code:
    function foobar()
    {
        global 
    $db;

        
    $res $db->Execute("select blah blah");
        
    // blah blah

    Regards,
    Christian.

  3. #3
    Join Date
    Jan 2008
    Posts
    49
    Plugin Contributions
    0

    Default Re: Problem with Function Scope. $db->Execute works inline, but not in a function?!

    Christian,

    You continue to be an awesome source of knowledge. THANK YOU!

    Josh

  4. #4
    Join Date
    May 2008
    Location
    South Australia
    Posts
    86
    Plugin Contributions
    1

    Default Re: Problem with Function Scope. $db->Execute works inline, but not in a function?!

    thankyou 2 :)

 

 

Similar Threads

  1. v1.2.x Fatal error: Call to a member function Execute() on a non-object
    By musikmachine in forum General Questions
    Replies: 1
    Last Post: 15 Feb 2012, 12:21 AM
  2. Replies: 2
    Last Post: 5 Jul 2008, 04:27 PM
  3. Call to a member function Execute() on a non-object- ZC v1.2.6
    By warpdesign in forum Installing on a Linux/Unix Server
    Replies: 10
    Last Post: 17 Jun 2008, 03:07 PM
  4. Fatal error: Call to a member function Execute() on a non-object
    By OLDTango in forum Installing on a Linux/Unix Server
    Replies: 6
    Last Post: 28 Jul 2007, 03:43 PM
  5. Fatal error: Call to a member function Execute()...
    By shooter.ca in forum General Questions
    Replies: 4
    Last Post: 3 Dec 2006, 02:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg