Re: Queries in QuickForm

From: Date: Fri, 16 Jan 2004 06:34:37 +0000
Subject: Re: Queries in QuickForm
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-10174@lists.php.net to get a copy of this message
I was reading following post regarding passing variable $dba to process_data function and the method was told to use global. Is this the best way ? Is using global variable good idea in PHP ? If not, what other way, I could use $dba inside process_data. Thanks Sanjay On 1 Sep 2003 at 13:55, Leonie wrote: > Here is a strange problem. > > I have two calls to the database on my QuickForm - the first to get > the data, and the second to update it: > > eg: > > require 'DB.php'; > .. > $dba = DB::connect($dsn, false); > ... > $result = $dba->query($sql); > .. > <data used in form> > .. > function process_data ($values) { > .. > $sql="..."; > $result = $dba->query($sql); > .. > } > > However this causes the error: > > Fatal error: Call to a member function on a non-object in e:\program > files\apache group\apache\htdocs\bmtus\docs\db_admin\users_edit.htm on > line 91 (line 91 is the line calling the second query) > > How do I fix this? put a global $dba; in your function process_data. Or do it via $GLOBALS['dba']->query($sql); The problem is that your $dba-object is not known inside the function and therefor query is no member function. Stefan --

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