problem in accessing postgres database

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

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 6
Joined: Tue Aug 07, 2012 3:31 am

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";
  $result = pg_query($conn, "SELECT * FROM district");
    if (!$result) {
      echo "An error occurred.\n";
  $num = pg_num_fields($result);
    while($row = pg_fetch_array($result)){
        for ($i=0; $i < $num; $i++)
	           $xml_result .= "<".pg_field_name($result, $i).">".$row[$i]."</".pg_field_name($result, $i).">";      
  echo $xml_result; 
I don't know if my code went wrong. Please help me from this.
Thanks in advance

php-forum Super User
php-forum Super User
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

Fri Aug 24, 2012 1:19 am

Post the error message.

Post Reply