Warning: pg_prepare() [function.pg-prepare]: Query failed: ERROR: prepared statement "Resource id #XX" already exists ~
Warning: pg_execute() [function.pg-execute]: Query failed: ERROR: bind message supplies XX parameters, but prepared statement "Resource id #XX" requires ~
のエラーが出た時は、
pg_prepare($pgsql,"適当な名称",$sql);
$result = pg_execute($pgsql,"適当な名称",$param);
のように2つ目の引数にクエリー名を付けると解消できる