www.webdeveloper.com
Results 1 to 5 of 5

Thread: Problems with Postgresql and PHP

  1. #1
    Join Date
    Aug 2009
    Location
    Virginia, USA
    Posts
    14

    Problems with Postgresql and PHP

    So, I'm new to using postgresql, and I'm having some issues getting data out using PHP. I am able to connect to the database, and I've printed my query string out and run it in pgAdmin III, and it works fine, but I do not get a result set back.

    PHP Code:
    $my_pg pg_connect('host='.$hostname.' dbname='.$dbGeomName.' user='.$username.' password='.$password);
    if (!
    $my_pg)
    {echo 
    "didn't connect<br>";}
    else
    {echo 
    "connected<br>";}

      function 
    colorCode($county)
      {
        
    $query "select \"1HR\" from \"Flood_Advisor\" where \"name\" ilike '".$county."%'";
        
    $result pg_query($my_pg$query) ;//or die ("failed to get results ".pg_last_error());
        
    if(!$result)
        { echo 
    "failed to get rows<br>"; }
        else
        {echo 
    "got rows<br>";}
        
    $resultArray pg_fetch_array($result0) ;//or die ("no rows");
        
    $stuff $resultArray['1HR'];
        echo 
    $query." ".$county." is ".$stuff."<br>";
      }
    colorCode("Augusta"); 
    for output I get:
    ---------------------------------------
    connected
    failed to get rows
    select "1HR" from "Flood_Advisor" where "name" ilike 'Augusta%' Augusta is
    ---------------------------------------
    So, it seems I am connecting to postresql, but fail to get a result, the query spit out does return a result though. Any help is greatly appreciated.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,225
    How about echoing the result of pg_last_error() in your error code if the pg_query() fails?

    (Or look into using pg_send_query(), pg_get_result() and pg_result_error() to possibly get more useful data.)
    Last edited by NogDog; 11-24-2009 at 11:36 AM.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2009
    Location
    Virginia, USA
    Posts
    14
    I added in:
    PHP Code:
        echo "row: ".pg_numrows($result)."<br>";
        echo 
    "error: ".pg_last_error(); 
    I also tried changing my query to:
    PHP Code:
    $result pg_query($my_pg$query) or die ("failed to get results ".pg_last_error()); 
    But in both instances, I do not receive an error message from pg_last_error, and I also do not receive a row count. I'm looking into the other methods you suggested now.

  4. #4
    Join Date
    Aug 2009
    Location
    Virginia, USA
    Posts
    14
    I just tried using pg_send_query() and pg_get_result(), and get the exact same output as with pg_query() and pg_fetch_array(). Also, pg_result_error() does the same as pg_last_error() and does not return any text.

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,225
    As far as I can see from the info you've provided and compared to the manual example page, I don't know why you don't get any error data. If you don't get any satisfaction here, I know there are at least a couple guys at the PHPbuilder.com forum who regularly use PostgreSQL and might have better insights into it than I do.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles