Page 1 of 1

problem in accessing postgres database

Posted: Tue Aug 07, 2012 5:00 am
by nandakishor
I am very new to PHP, I want to access postgres database using php script.
I checked php installation and is working fine. Also I enabled pgsql.dll in php.ini. But I dont know why my code is not working..
here is my code.

Code: Select all

<?
   //header("Content-type: text/xml");
   
  $conn = pg_pconnect("host=localhost dbname=test user=postgres password=nkr@123");
    
    if (!$conn) {
      echo "An error occurred.\n";
      exit;
      }
      
  $result = pg_query($conn, "SELECT * FROM district");
  
    if (!$result) {
      echo "An error occurred.\n";
      exit;
      }
      
  $xml_result="<resultxml>";
  $num = pg_num_fields($result);
  
    while($row = pg_fetch_array($result)){
      $xml_result.="<record>"; 
        for ($i=0; $i < $num; $i++)
          {   
	           $xml_result .= "<".pg_field_name($result, $i).">".$row[$i]."</".pg_field_name($result, $i).">";      
          }
          
      $xml_result.="</record>";
      }
  $xml_result.="</resultxml>";
  echo $xml_result; 
  
?>
I don't know if my code went wrong. Please help me from this.
Thanks in advance

Re: problem in accessing postgres database

Posted: Fri Aug 24, 2012 1:19 am
by johnj
Post the error message.