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
    Oct 2009
    Posts
    658
    What's the last error? Uncomment pg_last_error

    Check if this works.

    PHP Code:


      
    function colorCode($county)
      {
    $my_pg pg_connect('host='.$hostname.' dbname='.$dbGeomName.' user='.$username.' password='.$password);
    if (!
    $my_pg)
    {echo 
    "didn't connect<br>";}
    else
    {echo 
    "connected<br>";}
        
    $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"); 
    Good Luck

    Santos Systems

  3. #3
    Join Date
    Aug 2009
    Location
    Virginia, USA
    Posts
    14
    I had it uncommented out before, but both pg_result_error() and pg_last_error() do not return anything. pg_num_rows() also does not return anything. I have also tried using pg_send_query() and pg_get_result() with the same result. I have also tried using pg_ping() after failing to get a result set to make sure I still had a connection to the database. That ping was successful.

  4. #4
    Join Date
    Jan 2009
    Posts
    3,346
    Are you able to run tha query manually not using PHP? If it works then we know the problem is with the PHP and if it doesn't work there is a problem with the DB.

  5. #5
    Join Date
    Aug 2009
    Location
    Virginia, USA
    Posts
    14
    Yes, I am able to run the query fine manually, I have been printing them out and trying them through the query tool in pgAdmin. Before I put it into this function I had a hard coded query that did the exact same thing and worked....well obviously not the exact same thing or I wouldn't be having issues this time around, but I only changed the query, now I cannot get a result set. I am new to postgresql, until recently I've stuck to mySQL, but because this requires some spacial data to be stored I'm trying to use postgresql for the whole thing. I was hoping it was something real silly I missed being new to postgresql.

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