PHP Fatal error: Call to a member function Execute() on a non-object
<p>When I execute this code I get an error saying "PHP Fatal error:  Call to a member function Execute() on a non-object". The line that causes this error is line 96: $ok = $DB->Execute($sql, $aWhereParams); I have tried to solve this, but i wasn't succesfull. Probably the code doesn't return an object? How can I catch this error or is there something wrong with my code? Please help. Thanks!</p>

<p>SykWitIt</p>

<p><code></p>

<pre><code>&lt;?php

include_once 'config.php';
include_once('/apps/geoservices/apps/geoservices2.4/config/settings.php');
include_once('/apps/geoservices/apps/geoservices2.4/htdocs/utils.php');

if ($argc &lt; 2)
{
    echo "Usage: php daemon.php &lt;samba share&gt;\n";
    exit(1);
}
elseif (is_dir($argv[1]))
{
    global $base;
    $base = $argv[1];

    // Dir_walk recursively walks to the root directory and all the subdirectory's
    dir_walk('handleFile', $argv[1], array('xml'), true, '', $argv[1]);
}
else
{
    echo "The parameter given for the samba share is not a directory.\n";
    exit(1);
}

function handleFile($base, $dir, $filehandle)
{
    //Get the application name
    $application_name = substr($dir, 0, -1);
    $application_name = strtolower(str_replace('\\', '_', $application_name)."_".substr($filehandle, 0, strrpos($filehandle, '.')));


    // Set the parameters needed to insert the WMC into the database
    $aWhereParams = array();

    $file = $base.$dir.$filehandle;
    $aWhereParams['appname'] = strtolower($application_name);
    $aWhereParams['password'] = generatePassword();
    $aWhereParams['wmctitle'] = null;
    $aWhereParams['folder'] = null;
    $aWhereParams['startwmc'] = 'Y';
    $aWhereParams['userid'] = null;

    $DB = createDatabaseConnection($dbconnect, $dbuser, $dbpasswd);

    if ($aWhereParams['folder'] !== null) 
    {
        // check if folder is already created
        $sql = "SELECT FOLDERID FROM WMCFOLDERS WHERE FOLDERTITLE = :folder AND APPLICATION=:appname";
        $ok = $DB-&gt;Execute($sql, $aWhereParams);
        if ($ok) 
        {
            $myArray = $ok-&gt;GetArray();
            if (empty($myArray)) 
            {
                // insert the folder into WMCFOLDERS
                createWMCDirectory($DB, $aWhereParams);
            } 
            else 
            {
                foreach ($myArray as $row) 
                {
                    $aWhereParams['folderid'] = $row['FOLDERID'];
                }
            }
        }
    } 
    else 
    {
        $aWhereParams['folderid'] = null;
    }

    $folderIdValue;
    if ($aWhereParams['folderid'] === null) 
    {
        $folderIdValue = 'IS NULL';
    } 
    else 
    {
        $folderIdValue = '='.$aWhereParams['folderid'];
    }

    $titleValue;
    if ($aWhereParams['wmctitle'] === null) 
    {
        $titleValue = 'IS NULL';
    } 
    else 
    {
        $titleValue = '='.$DB-&gt;qstr($aWhereParams['wmctitle'], get_magic_quotes_gpc());
    }

    // check if there is an existing entry, if so update it
    $sql = "SELECT APPLICATION FROM WMC WHERE STARTWMC=:startwmc AND APPLICATION=:appname AND FOLDERID ".$folderIdValue." AND TITLE ".$titleValue;
    $ok = $DB-&gt;Execute($sql, $aWhereParams);
    if ($ok) 
    {
        $myArray = $ok-&gt;GetArray();
        if (empty($myArray)) 
        {   
            // we need to insert a new entry
            $sql = "insert into WMC (USERID, APPLICATION, FOLDERID, TITLE, STARTWMC, WMC) values (null, :appname, :folderid, :wmctitle, :startwmc, null)";

            // Combine WMC name with the password for the new entry
            $aWhereParams['appname'] .= $aWhereParams['password'];

            $ok = $DB-&gt;Execute($sql, $aWhereParams);
            if (!$ok) 
            {
                handleDBError($DB);
            }

            insertCLOB($DB, $file, $aWhereParams['appname'], $aWhereParams['folderid'] , $aWhereParams['wmctitle']);

            foreach ($GLOBALS['emailadresses'] as $dienst =&gt; $emailaddress)
            {
                if ($dienst == $aWhereParams['appname'])
                {
                    // Set the email properties
                    $to = $emailaddress;
                    $subject = "Nieuwe WMC toegevoegd";
                    $message = "Er is een nieuwe WMC toegevoegd. Je kunt deze bekijken door naar het adres ".getURL()." te gaan en in te loggen met \n";
                    $message .= "gebruikersnaam: ".$aWhereParams['appname'];
                    $message .= "wachtwoord: ".$aWhereParams['password'];

                    $from = "test@blabla.com";
                    $headers = "From:".$from;

                    // Combine all property's and send the email
                    mail($to, $subject, $message, $headers);
                }
            }
        } 
        else 
        {
            insertCLOB($DB, $file, $aWhereParams['appname'], $aWhereParams['folderid'] , $aWhereParams['wmctitle']);

            foreach ($GLOBALS['emailadresses'] as $dienst =&gt; $emailaddress)
            {
                if ($dienst == $aWhereParams['appname'])
                {
                    // Set the email properties
                    $to = $emailaddress;
                    $subject = "Nieuwe WMC toegevoegd";
                    $message = "Er is een nieuwe WMC toegevoegd. Je kunt deze bekijken door naar het adres ".getURL()." te gaan.";

                    $from = "test@blabla.com";
                    $headers = "From:".$from;

                    // Combine all property's and send the email
                    mail($to, $subject, $message, $headers);
                }
            }
        }
    } 
    else 
    {
        handleDBError($DB);
    }

    echo "WMC '".$aWhereParams['wmctitle']."' loaded OK in folder '".$aWhereParams['folder']."'\n";
    echo "    for ".$aWhereParams['appname'].", $dbuser@$dbconnect\n";
}

// Generate a random password
function generatePassword()
{
    $length = 8;

    $password = "";
    $possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";

    $maxlength = strlen($possible);

    if ($length &gt; $maxlength)
        $length = $maxlength;

    $i = 0; 
    while ($i &lt; $length) 
    { 
      $char = substr($possible, mt_rand(0, $maxlength-1), 1);

      if (!strstr($password, $char)) 
      { 
        $password .= $char;
        $i++;
      }
    }

    return $password;
}

function getURL()
{
    //This will be URL
    return gethostname()."/apps/geoservices/";
}

function dir_walk($callback, $dir, $types = null, $recursive = false, $baseDir = '', $base)
{
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false)
        {
            if ($file === '.' || $file === '..')
            {
                continue;
            }
            if (is_file($dir . $file))
            {
                if (is_array($types))
                {
                    if (!in_array(strtolower(pathinfo($dir . $file, PATHINFO_EXTENSION)), $types, true))
                    {
                        continue;
                    }
                }
                $callback($base, $baseDir, $file);
            }
            elseif($recursive &amp;&amp; is_dir($dir . $file))
            {
                dir_walk($callback, $dir . $file . DIRECTORY_SEPARATOR, $types, $recursive, $baseDir . $file . DIRECTORY_SEPARATOR, $base);
            }
        }
        closedir($dh);
    }
}
?&gt;
</code></pre>

<p><code></p>

<p>This the function that creates an Oracle database connection given a connect string, user and pwd</p>

<pre>function createDatabaseConnection($dbconnect, $dbuser, $dbpasswd)
{
  // we need adodb
  require_once('/usr/share/php/adodb/adodb.inc.php');

  // make sure that the OCI extension is loaded
  $szOCIModule = "php_oci8";
  if (!extension_loaded("oci8"))
      dl($szOCIModule . "." . PHP_SHLIB_SUFFIX);

   $DB = NewADOConnection('oci8');
   $DB-&gt;PConnect($dbconnect, $dbuser, $dbpasswd);
   if (!$DB) return false;
   if (!$DB-&gt;IsConnected()) return false;
   return $DB;
}
</code></pre>

<p>My other script works fine, the same DBConnection. The main difference is that in the script(with the error) i use function handleFile with some extra params. The code is here:</p>

<pre>&lt;?php

include_once(dirname(__FILE__).'/../config/settings.php');
include_once(dirname(__FILE__).'/../htdocs/utils.php');

if ($argc &lt; 3) {
  echo "Usage: insertwmc.php &lt;application&gt; &lt;wmc file&gt; [title] [folder]\n";
  echo "\n";
  echo "Inserts the wmc file as a CLOB into the userprofile database for a specific application\n";
  echo "\n";
  echo "The wmc file should be an absolute path.\n";
  echo "\n";
  echo "If no title is specified, the WMC will become the default WMC for the application\n";
  echo "\n";
  exit(1);
}

$aWhereParams = array();

$file=$argv[2];
$aWhereParams['appname'] = strtolower($argv[1]);
$aWhereParams['wmctitle'] = null;
$aWhereParams['folder'] = null;
$aWhereParams['startwmc'] = 'Y';
if (isset($argv[3])) {
  $aWhereParams['wmctitle'] = $argv[3];
  $aWhereParams['startwmc'] = 'N';
}
if (isset($argv[4])) {
  $aWhereParams['folder'] = $argv[4];
}
$aWhereParams['userid'] = null;

$DB = createDatabaseConnection($dbconnect, $dbuser, $dbpasswd);

if ($aWhereParams['folder'] !== null) {
  // check if folder is already created
  $sql = "SELECT FOLDERID FROM WMCFOLDERS WHERE FOLDERTITLE = :folder AND APPLICATION=:appname";
  $ok = $DB-&gt;Execute($sql, $aWhereParams);
  if ($ok) {
    $myArray = $ok-&gt;GetArray();
    if (empty($myArray)) {
      // insert the folder into WMCFOLDERS
      createWMCDirectory($DB, $aWhereParams);
    } else {
      foreach ($myArray as $row) {
        $aWhereParams['folderid'] = $row['FOLDERID'];
      }
    }
  }
} else {
  $aWhereParams['folderid'] = null;
}

$folderIdValue;
if ($aWhereParams['folderid'] === null) {
  $folderIdValue = 'IS NULL';
} else {
  $folderIdValue = '='.$aWhereParams['folderid'];
}

$titleValue;
if ($aWhereParams['wmctitle'] === null) {
  $titleValue = 'IS NULL';
} else {
  $titleValue = '='.$DB-&gt;qstr($aWhereParams['wmctitle'], get_magic_quotes_gpc());
}

// check if there is an existing entry, if so update it
$sql = "SELECT APPLICATION FROM WMC WHERE STARTWMC=:startwmc AND APPLICATION=:appname AND FOLDERID ".$folderIdValue." AND TITLE ".$titleValue; 
$ok = $DB-&gt;Execute($sql, $aWhereParams);
if ($ok) {
  $myArray = $ok-&gt;GetArray();
  if (empty($myArray)) {
    // we need to insert a new entry
    $sql = "insert into WMC (USERID, APPLICATION, FOLDERID, TITLE, STARTWMC, WMC) values (null, :appname, :folderid, :wmctitle, :startwmc, null)";
    $ok = $DB-&gt;Execute($sql, $aWhereParams);
    if (!$ok) {
      handleDBError($DB);
    }
    insertCLOB($DB, $file, $aWhereParams['appname'], $aWhereParams['folderid'] , $aWhereParams['wmctitle']);
  } else {
    insertCLOB($DB, $file, $aWhereParams['appname'], $aWhereParams['folderid'] , $aWhereParams['wmctitle']);
  }
} else {
  handleDBError($DB);
}

echo "WMC '".$aWhereParams['wmctitle']."' loaded OK in folder '".$aWhereParams['folder']."'\n";
echo "    for ".$aWhereParams['appname'].", $dbuser@$dbconnect\n";

?&gt;
</code></pre>
