Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help converting MySQL connection to PostgrSQL 1

Status
Not open for further replies.

Xaqte

IS-IT--Management
Oct 4, 2002
971
US
Ok, I've got the following MySQL connection working in PHP:
Code:
      $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
      mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());

Now, I cannot figure out how to change this to a PostgrSQL connection. I've tried (to begin with):
Code:
      $this->connection = pg_connect("host=localhost user=me password=#y7u20") or die(pg_last_error());

This gives me the error:
Code:
Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: Password authentication failed for user "me"

I know that I'm using the correct username and password, because I was able to create tables with this user earlier with a Perl script.

Any help/thoughts would greatly be appreciated!

X
 
Thanks for the reply, I've tried this:
Code:
$this->$connection = pg_connect("host=localhost dbname=mydb user=me password=#y7u20");
And this:
Code:
$this->$connection = pg_pconnect("host=localhost dbname=mydb user=me password=#y7u20");

I'm still getting the same error. It wouldn't be because my password begins with "#", would it?

Again, any thoughts/help would greatly be appreciated!

X
 
Woops, that was one bad spelling error... I meant this for each of the above code blocks:
Code:
$this->connection

Instead of:
Code:
$this->$connection

Sorry for any confusion!
 
Xaqte said:
Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: Password authentication failed for user "me"

I think that pretty much is self explanatory, somethng is wrong with the password. Have you tried changing it to something that doesn't start with a #

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I'd be curious to see the relevant portions of your pg_hba.conf file, showing authentication methods for localhost. Also, is it possible you have selinux enabled? That has cause me some headaches in the past.

----
JBR
 
I finally figured it out... I just needed to remove the "host" portion. Go figure!

X
 
Glad you sorted it out.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top