From: Papp Gyozo <pgerzson@freestart.hu>
To: Zavier Sheran <zsheran@yahoo.com>
To: pgsql-php@postgresql.org
Subject: Re: Nextval again
Date: Sat, 13 Oct 2001 15:11:03 +0200
Message-ID: <00bc01c153ef$b5d1cfc0$01fdfea9@jaguar> (raw)
References: <20011013045140.50099.qmail@web14401.mail.yahoo.com>
Hello,
> I did run different queries like
No matter what queries are executed as long as they are valid. :)
>
> $number = pg_Exec ($db_connect, "SELECT
> nextval('members_recordid_seq')");
>
> $number = pg_Exec ($db_connect, "SELECT last_value
> FROM members_recordid_seq");
>
> What I get when I "echo $number;" is "Resource id #2",
> no matter what number the sequence is at (currently
> 19).
Yes, because as the PHP manual says:
pg_Exec() returns a valid resource id on success, or FALSE on failure.
It means that you have to fetch the rows from the result set pointed by
this resource id. To describe it very loosely, the resource id only points
to a memory location where the rows returned by a SELECT statement are
stored.
So you must :
$result = pg_exec($db_connnect, "SELECT -- your query goes here...;");
for ($row = 0; $row < pg_numrows($result); $row++)
{
$record = pg_fetch_row($result, $row);
print_r($record);
}
//if you are interested only a specific row (ie.: thwe 1st one, like above)
$result = pg_Exec ($db_connect, "SELECT nextval('members_recordid_seq')");
list($number) = pg_fetch_row($result, 0); // row numbering starts from 0.
>
> If I run the same queries in phpPgAdmin I get the
> correct results.
phpPgAdmin does this fetching automatically.
> I run PHP 4.04 and PgSQL 7.03
You are strongly encouraged to upgrade both.
> Any ideas?
>
> __________________________________________________
> Do You Yahoo!?
> Make a great connection at Yahoo! Personals.
> http://personals.yahoo.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: pgerzson@freestart.hu, zsheran@yahoo.com
Subject: Re: Nextval again
In-Reply-To: <00bc01c153ef$b5d1cfc0$01fdfea9@jaguar>
References: <20011013045140.50099.qmail@web14401.mail.yahoo.com> <00bc01c153ef$b5d1cfc0$01fdfea9@jaguar>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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