#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    3
    Rep Power
    0

    is not a valid PostgreSQL link resource


    I have PHP code for a PSQl database that runs on my Linux boxbut not on the University SGI server's installation of PSQL.

    Here are the errors:

    Warning: 1 is not a valid PostgreSQL link resource in /home/std/yn99ab/public_html/project/private/po_view.php4 on line 153

    Warning: 1 is not a valid PostgreSQL link resource in /home/std/yn99ab/public_html/project/private/po_view.php4 on line 154

    Warning: Supplied argument is not a valid PostgreSQL result resource in /home/std/yn99ab/public_html/project/private/po_view.php4 on line 156

    Here is the code:

    function db_get_dist($dbn, $dbu, $dbp, $distid)
    {
    $db = pg_connect("dbname=$dbn user=$dbu password=$dbp");
    $query = "SELECT * FROM Distributor WHERE distid='$distid'";
    $result = pg_exec($db, $query); <<<<LINE 153
    pg_close($db); <<<<LINE 154

    $dist = pg_fetch_array($result, $i);<<<<LINE 156

    return $dist;
    }


    What could cause this problem?

    Thanks

    Yanik
  2. #2
  3. Modding: Oracle MsSQL Firebird
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2001
    Location
    Outside US
    Posts
    8,527
    Rep Power
    538
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    3
    Rep Power
    0
    Well thansk for the info. You pointed me in the right direction. Believe it or not I have about 25 different queries where I use the same connect line:

    $db = pg_connect("dbname=$dbn user=$dbu password=$dbp");

    But after your post I tried specifying the host:

    $db = pg_connect("host=sandcastle dbname=$dbn user=$dbu password=$dbp");

    It worked fine.

    So that I know for future reference, does that mean the university server is:

    listening on port 5432
    or
    using a socket?

    Also, if you know, why is this problem only affecting 2 queries/connections out of about 25 different ones?

    For example this query works fine without host parameter:

    function db_get_partlist($dbn, $dbu, $dbp, $poid, $distid)
    {
    $db = pg_connect("dbname=$dbn user=$dbu password=$dbp");
    $query = "SELECT * FROM Quote WHERE estid='$poid' AND distid='$distid'";
    $result = pg_exec($db, $query);
    pg_close($db);
    pg_close($db);
    $numrows = pg_numrows($result);
    for($i=0; $i<$numrows; $i++)
    {
    $plist[$i] = pg_fetch_array($result, $i);
    }

    return $plist;
    }

    Thanks again pabloj!

    Yanik
  6. #4
  7. Modding: Oracle MsSQL Firebird
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2001
    Location
    Outside US
    Posts
    8,527
    Rep Power
    538
    Funny, I think that pg is listening on 5432 (try telnet to it, to be sure).
    But I do not know why other queries worked, is everything on the same machine?
    Hope this helps!
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    3
    Rep Power
    0
    From what I can tell it's listening on port 5432.

    I actually had more strnge problems, that are now solved. I'll post waht I did in case it would help others.

    I had a for loop calling one of my fucntions ot get data from the PSQL database. Every second iteration I was getting:

    # is not a valid PostgreSQL link resource ...

    Even with the port specified.

    By changing:

    $db = pg_connect("host $dbh dbname=$dbn user=$dbu password=$dbp");

    To:

    $db = pg_pconnect("host $dbh dbname=$dbn user=$dbu password=$dbp");

    Everythign worked fine.

    so using pg_pconnect (persistent connection) I solved the problem.

    It probably worked on my Linux box with the original code because of some configuration setting. But I have no idea which one.

    YN
  10. #6
  11. Modding: Oracle MsSQL Firebird
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2001
    Location
    Outside US
    Posts
    8,527
    Rep Power
    538

IMN logo majestic logo threadwatch logo seochat tools logo