You're mixing the two possible syntaxes for a pg_connect. They can either be:
pg_connect ("hostname","port","options","tty","dbname");
OR
pg_connect ("dbname=database host=hostname port=number tty=tty options=opts user=username password=pwd");
Other common pitfalls:
You can only get the lastoid from postgres via PHP, not the last unique key inserted.
Max backends by default is compiled in at 32 (WAY too low) and needs to be recompiled on heavily worked sites to be at least 64 or 128.
To create a column that is an autoincrementing primary key, use the SERIAL keyword for it's type, like so:
create table test (name text, id_num SERIAL);
This will create a sequence and index to go with your table. Currently a drop table will drop the index but you have to drop the sequence by hand.