Обсуждение: getting integer result from 4.1

Поиск
Список
Период
Сортировка

getting integer result from 4.1

От
Mark Nelson
Дата:
Hi,

I have an update statement that queries a db and updates wheere
it finds matches. I know that postgres itself returns the number
of rows it updates because when I run the query in psql, I get
UPDATE 1, or whatever the num of rows it updates.

My question is how do I get that result with PHP? I have tried
this
        $update = //this is where I execute the query
    $updates = pg_fetch_row($update, 0);
    echo "rows updated=".$updates[0]."<br>";

But that blows up with
Warning: Unable to jump to row 0 on PostgreSQL result index 6 in
my php doc.

Same thing with pg_fetch_array. I know there is a result, because
if I check it as a boolean (ex.  if ($update) ) it always comes
back true, even when 0 rows are updated (UPDATE 0). I imagine
this is where pg_affected_rows in PHP 4.2 works well, but I am
using 4.1.2, so that isn't an option.

thanks for your time,
/mark


Re: getting integer result from 4.1

От
brew@theMode.com
Дата:
Mark.....

>         $update = //this is where I execute the query
>     $updates = pg_fetch_row($update, 0);
>     echo "rows updated=".$updates[0]."<br>";
>
> But that blows up with
> Warning: Unable to jump to row 0 on PostgreSQL result index 6 in
> my php doc.

....probably because there is nothing returned from your query (there is
no row zero, or any other row).

Check into the PHP PostgreSQL funtion pg_numrows docs at php.net (or
pg_num_rows, the name has recently changed depending on which version PHP
you are using).

I usually query, then check the number of rows and loop through them only
if something is returned, else I print out a 'Nothing Found' type of
message.

brew




Re: getting integer result from 4.1

От
brew@theMode.com
Дата:
> I have an update statement that queries a db and updates wheere
> it finds matches.

Ooops, I just noticed it was an update statement, but there is a function
for that, too, pg_affected_rows, I think.

brew



Re: getting integer result from 4.1

От
"scott.marlowe"
Дата:
On Fri, 6 Dec 2002 brew@theMode.com wrote:

>
> > I have an update statement that queries a db and updates wheere
> > it finds matches.
>
> Ooops, I just noticed it was an update statement, but there is a function
> for that, too, pg_affected_rows, I think.

Note that the pg_affected_rows was added as of php version 4.2.0, so
you'll need to upgrade from 4.1 to get that functionality.

4.3 is in RC2 or so right now, so you might wanna wait a week or two for
the new version of php to come out.


Re: getting integer result from 4.1

От
Mark Nelson
Дата:
Problem solved. There is a command no longer listed among
the php documentation (since it has been updated for the
newest releases) called pg_cmdtuples which does I guess the
same thing as pg_affected_rows. That does just what I need
in 4.1. Maybe I should find a 4.1 version of the
documentation (or update to PHP 4.2/3)

thanks for everyone's help in looking into this.

/mark

****************************************
On Fri, 6 Dec 2002, scott.marlowe wrote:

> On Fri, 6 Dec 2002 brew@theMode.com wrote:
>
> >
> > > I have an update statement that queries a db and updates wheere
> > > it finds matches.
> >
> > Ooops, I just noticed it was an update statement, but there is a function
> > for that, too, pg_affected_rows, I think.
>
> Note that the pg_affected_rows was added as of php version 4.2.0, so
> you'll need to upgrade from 4.1 to get that functionality.
>
> 4.3 is in RC2 or so right now, so you might wanna wait a week or two for
> the new version of php to come out.
>
>