Re: Fatal error when calling DB in function

From: Date: Wed, 05 Dec 2007 05:17:24 +0000
Subject: Re: Fatal error when calling DB in function
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-28268@lists.php.net to get a copy of this message
batterhead schrieb:
If I process this query outside of a function it works just fine. If I call it using a function as show below I get the error: Fatal error: Call to a member function on a non-object in /Library/WebServer/...
You find the answer here: http://www.php.net/manual/en/language.variables.scope.php
<?php require_once("include/dbConnect.inc.php"); function getProps() {
e.g. this can help: | global $db;
$res = $db->query('SELECT * FROM properties'); while ($res->fetchInto($prop)) {
    echo $prop->id . "<br />";
} $res->free(); } getProps(); ?>
Regards, Carsten

« previous php.pear.general (#28268) next »