coreilly
11-24-2009, 10:24 AM
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.
$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($result, 0) ;//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.
$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($result, 0) ;//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.