pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedpg_fetch_object
3+ messages / 2 participants
[nested] [flat]
* pg_fetch_object
@ 2005-09-24 00:55 John DeSoi <desoi@pgedit.com>
2005-09-24 02:44 ` Re: pg_fetch_object Michael Fuhr <mike@fuhr.org>
0 siblings, 1 reply; 3+ messages in thread
From: John DeSoi @ 2005-09-24 00:55 UTC (permalink / raw)
To: php-db <php-db@lists.php.net>; pgsql-php
I'm using PHP 5.0.4, PostgreSQL 8.0.2.
Docs say (http://www.php.net/manual/en/function.pg-fetch-object.php):
object pg_fetch_object ( resource result [, int row [, string
class_name [, array params]]] )
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?
Thanks,
John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: pg_fetch_object
2005-09-24 00:55 pg_fetch_object John DeSoi <desoi@pgedit.com>
@ 2005-09-24 02:44 ` Michael Fuhr <mike@fuhr.org>
2005-09-24 13:17 ` Re: pg_fetch_object John DeSoi <desoi@pgedit.com>
0 siblings, 1 reply; 3+ messages in thread
From: Michael Fuhr @ 2005-09-24 02:44 UTC (permalink / raw)
To: John DeSoi <desoi@pgedit.com>; +Cc: php-db <php-db@lists.php.net>; 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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: pg_fetch_object
2005-09-24 00:55 pg_fetch_object John DeSoi <desoi@pgedit.com>
2005-09-24 02:44 ` Re: pg_fetch_object Michael Fuhr <mike@fuhr.org>
@ 2005-09-24 13:17 ` John DeSoi <desoi@pgedit.com>
0 siblings, 0 replies; 3+ messages in thread
From: John DeSoi @ 2005-09-24 13:17 UTC (permalink / raw)
To: Michael Fuhr <mike@fuhr.org>; +Cc: php-db <php-db@lists.php.net>; pgsql-php
Hi Michael,
On Sep 23, 2005, at 10:44 PM, Michael Fuhr wrote:
> Works here with PHP 5.0.4 and PostgreSQL 8.0.3:
Thanks for the example, it helped me figure out my dumb mistake. I
copied code from another place using a PHP abstraction library. I was
calling 'db_fetch_object' not 'pg_fetch_object'.
Thanks much,
John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-09-24 13:17 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-09-24 00:55 pg_fetch_object John DeSoi <desoi@pgedit.com>
2005-09-24 02:44 ` Michael Fuhr <mike@fuhr.org>
2005-09-24 13:17 ` John DeSoi <desoi@pgedit.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox