Board index   FAQ   Search  
Register  Login
Board index php forum :: Database Other Database Engines

problem in accessing postgres database

Do you have questions regarding other database enginges (not MySQL) -- ask here!

Moderators: macek, egami, gesf

problem in accessing postgres database

Postby nandakishor » Tue Aug 07, 2012 5:00 am

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
nandakishor
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Aug 07, 2012 3:31 am

Re: problem in accessing postgres database

Postby johnj » Fri Aug 24, 2012 1:19 am

Post the error message.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to Other Database Engines

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron