Re: PostgreSQL driver and internal row counting

From: Date: Sun, 07 Oct 2001 12:00:38 +0000
Subject: Re: PostgreSQL driver and internal row counting
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-67474@lists.php.net to get a copy of this message
On Sun, 7 Oct 2001, Sebastian Bergmann wrote: > This patch > > > http://cvs.php.net/diff.php/php4/ext/pgsql/pgsql.c?r1=1.111&r2=1.112&f=u > > allowed the PostgreSQL driver to do internal row counting when > iterating through a result set. But how do I use it? I still do > something like > > pg_fetch_array($result, $row++, PGSQL_ASSOC) > > and manually count the rows. I'd test it, but I currently have no > PostgreSQL installation at my avail. I had a play with this patch because I am giving a total break down of Postgres at the 2001 PHP Conference. pg_fetch_array(), pg_fetch_row(), pg_fetch_object() and pg_result are all affected by this patch. They now have the following form: array pg_fetch_row(int result [, int row]) object pg_fetch_object(int result [, int row [, int result_type]]) array pg_fetch_array(int result [,int row [, int result_type]]) mixed pg_result(int result [, int row], mixed fieldname) If this is the first call to either function and 'row' is not given, the internal row counter is set to zero. Otherwise, in the case of the first three, the row is returned and the row counter is incremented by one. In the case of pg_result(), the result for 'fieldname' at the row pointed to by the row point is returned. If the value of the internal row counter > number of rows returned, the functions return false. For pg_fetch_(array|object)(), if 'row' is omitted, 'result_type' must also be omitted - PGSQL_BOTH is assumed. Naturally, if you make the mistake of doing something like: $row = pg_fetch_array($res,PGSQL_ASSOC); $row will be the result of 2nd row (PGSQL_ASSOC == 1). Gavin

« previous php.dev (#67474) next »