Re: Nextval again

From: "Papp Gyozo" <pgerzson(at)freestart(dot)hu>
To: "Zavier Sheran" <zsheran(at)yahoo(dot)com>, <pgsql-php(at)postgresql(dot)org>
Subject: Re: Nextval again
Date: 2001-10-13 13:11:03
Message-ID: 00bc01c153ef$b5d1cfc0$01fdfea9@jaguar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

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

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Emmanuel SARACCO 2001-10-13 17:14:36 temp tables and pg_pconnect()
Previous Message Zavier Sheran 2001-10-13 04:51:40 Nextval again