The pg_fieldname function only returns the unqualified name from the select statement. example:
select c.name, con.name from customer c, contacts con where con.customer_id = c.id;
pg_fieldname will return "name" for both fields instead of c.name and con.name.
This is a PostgreSQL limitation, not a PHP limitation.
if you need different field names you should use :
select c.name as customer_name, con.name as contact_name from customer c, contacts con where con.customer_id = c.id;
then pg_fieldname will return "customer_name" and "contact_name"