#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    361
    Rep Power
    13

    reset a postgres resultset


    after recently being convinced by reading the arguments put forward by all the postgreSQL proponents out there (notably rycamor), I have downloaded postgres and compiled it into my PHP.

    i am currently in the process of writing my own db abstraction class to handle postgres and mysql (i have a fear of using code i haven't written myself, so that's why I haven't just downloaded a class), which will probably appear shortly on the PHP forum to invite comments.

    i am trying to implement a method on my recordset class to "reset" the resultset back to the first row returned, like mysql_data_seek can be used to do. closest I've got is on the post A dirty solution to converting mysql_data_seek to postgres -> pros please comment but that suggestion [pg_fetch_row($degree_result, -1)] throws a warning.

    so, how does one do this?
    Little more than a playground for the bugs that live beneath us...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    409
    Rep Power
    13
    Hmmmm....I'll try and come up with a better explanation for this, but basically, resetting a result in Postgres is NOT needed at all.

    That's why you don't see a Postgres "pg_data_seek" type function, because it's not needed.

    See here for more info:

    http://archives.postgresql.org/pgsql...1/msg00123.php
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    361
    Rep Power
    13

    i can see...


    ... that I am heading for a few conceptual changes here...!

    Thanks, Ted... let me explain what I'm heading for:

    i like my rows as associative/numbered arrays, like when they come from mysql_fetch_array, so i used the function pg_fetch_array, about which the php manual says:

    array pg_fetch_array ( resource result, int row [, int result_type])

    Note: From 4.1.0, row became optional. Calling pg_fetch_array() will increment internal row counter by 1.

    so, using the point from the note, i have been using pg_fetch_array as a direct substitute for mysql_fetch_array.

    so, now i guess i need a reset...! however if i use one of the fetch functions and put the zero in for the row number, it still advances the internal pointer by one... so my next call to my get_row function gives me the second row...

    i'll give it some thought...

    FYI i'm on PHP4.2.2/Apache 1.3.26/RedHat7.3 (i like shiny new software!)
    Little more than a playground for the bugs that live beneath us...
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    361
    Rep Power
    13

    for want of something better:


    @pg_fetch_row($rs, -1);

    i dislike suppressing known errors, as one day you're going to get a big momma error and PHP will blithely walk on by...!

    however, for the time being...
    Little more than a playground for the bugs that live beneath us...

IMN logo majestic logo threadwatch logo seochat tools logo