You can get close.
With postgresql, like mysql, there is a fetch_array type statement.
What you do is connect to the database, and run a single query of:
$result=pg_exec($conn,"select * from table limit 1;");
If there's at least one row in the database, then you can grab the names of the fields like so:
$array=pg_fetch_array($result,$row);
But if not, then you'll have to enumerate them one by one with the pg_numfields, pg_fieldtype, and pg_fieldname commands, like so:
for ($i=0;$i<pg_numfields($result);$i++){
print "Field $i name: ".pg_fieldname($result,$i);
print "Field $i type: ".pg_fieldtype($result,$i);
print "<BR>\n";
stuff them in an array:
$fields[$i][name]=pg_fieldname($result,$i);
$fields[$i][type]=pg_fieldtype($result,$i);
}