problem in accessing postgres database

A

Anonymous

Guest
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:
<?
   //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
 
Back
Top