Re: Nextval again

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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




[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux