pqsql fieldnames

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • meltedown

    pqsql fieldnames

    This is a function that returns the names a table field on a pgsql database

    $skips is simply the field names that will be left out of the result.

    This function acts differently on two different servers
    Both servers have PHP Version 4.3.10-10ubuntu4.3
    AND PostgreSQL(libp q) Version 7.4.6

    On one server, the function acts as expected, returning an array with
    the field names. On the other server, some of the field names come up 6
    times instead of once. Apparently, something in my sql is creating
    multiple values for some names. My sql is kind of fuzzy, can you see the
    mistake ?

    function fieldnames($tab le, $skips=NULL){
    $sql="SELECT a.attname FROM pg_attribute a, pg_class c WHERE
    c.relname = '$table' AND a.attnum > 0 AND a.attrelid = c.oid ORDER BY
    a.attnum ";
    $result=q($sql) ;
    $skips=mkarr($s kips);
    while($row=pg_f etch_assoc($res ult)){
    if(in_array($ro w['attname'], $skips))continu e;
    $fnames[]=$row['attname'];
    }
    return $fnames;
    }
  • Jerry Stuckle

    #2
    Re: pqsql fieldnames

    meltedown wrote:[color=blue]
    > This is a function that returns the names a table field on a pgsql database
    >
    > $skips is simply the field names that will be left out of the result.
    >
    > This function acts differently on two different servers
    > Both servers have PHP Version 4.3.10-10ubuntu4.3
    > AND PostgreSQL(libp q) Version 7.4.6
    >
    > On one server, the function acts as expected, returning an array with
    > the field names. On the other server, some of the field names come up 6
    > times instead of once. Apparently, something in my sql is creating
    > multiple values for some names. My sql is kind of fuzzy, can you see the
    > mistake ?
    >
    > function fieldnames($tab le, $skips=NULL){
    > $sql="SELECT a.attname FROM pg_attribute a, pg_class c WHERE
    > c.relname = '$table' AND a.attnum > 0 AND a.attrelid = c.oid ORDER BY
    > a.attnum ";
    > $result=q($sql) ;
    > $skips=mkarr($s kips);
    > while($row=pg_f etch_assoc($res ult)){
    > if(in_array($ro w['attname'], $skips))continu e;
    > $fnames[]=$row['attname'];
    > }
    > return $fnames;
    > }[/color]

    Since the problem seems to be in the SQL code, might I suggest that a
    PostgreSQL newsgroup would be more appropriate?


    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    Working...