X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4BB78D938F for ; Fri, 23 Sep 2005 23:44:31 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 73006-03 for ; Sat, 24 Sep 2005 02:44:26 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id D9730D9388 for ; Fri, 23 Sep 2005 23:44:27 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j8O2iL5E058979 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Sep 2005 20:44:23 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j8O2iKWj023571; Fri, 23 Sep 2005 20:44:20 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j8O2iKTD023570; Fri, 23 Sep 2005 20:44:20 -0600 (MDT) (envelope-from mfuhr) Date: Fri, 23 Sep 2005 20:44:20 -0600 From: Michael Fuhr To: John DeSoi Cc: php-db , pgsql-php@postgresql.org Subject: Re: pg_fetch_object Message-ID: <20050924024420.GA23515@winnie.fuhr.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200509/18 X-Sequence-Number: 3258 On Fri, Sep 23, 2005 at 08:55:44PM -0400, John DeSoi wrote: > pg_fetch_object() returns an object with properties that correspond > to the fetched row's field names. It can optionally instantiate an > object of a specific class, and pass parameters to that class's > constructor. > > I'm passing a class name string as the third parameter, but I only > get back a stdClass object. I also added an array of params as the > 4th parameter to pass to the constructor, but it does not appear to > be called. > > Has anyone successfully used this to create a class other than stdClass? Works here with PHP 5.0.4 and PostgreSQL 8.0.3: class Foo { function Foo($arg) { print "DEBUG: Foo($arg)\n"; } } pg_connect("dbname=test user=test password=test"); $result = pg_query("SELECT 'foo' AS val"); $obj = pg_fetch_object($result, 0, 'Foo', array("test")); var_dump($obj); pg_close(); The above code produces the following output: DEBUG: Foo(test) object(Foo)#1 (1) { ["val"]=> string(3) "foo" } Could you post a minimal example that doesn't work? -- Michael Fuhr