From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | John DeSoi <desoi(at)pgedit(dot)com> |
Cc: | php-db <php-db(at)lists(dot)php(dot)net>, pgsql-php(at)postgresql(dot)org |
Subject: | Re: pg_fetch_object |
Date: | 2005-09-24 02:44:20 |
Message-ID: | 20050924024420.GA23515@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-php |
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
From | Date | Subject | |
---|---|---|---|
Next Message | John DeSoi | 2005-09-24 13:17:20 | Re: pg_fetch_object |
Previous Message | John DeSoi | 2005-09-24 00:55:44 | pg_fetch_object |