Jump to content

Archived

This topic is now archived and is closed to further replies.

caduceus

PostgreSQL SECURE CONNECTION - PHP

Recommended Posts

HI,

Can anybody help how to connect to PostgreSQL form PHP over SSL.

I know PG_Connect can be used with option requiressl, but I did not find any resource about that. Do you have some links to web pages where this is well explained?

Any other way how to remotely connect to Postgres securely?

Share this post


Link to post
Share on other sites

Check out Justin Vincents "ez_sql" database wrapper class, modify it for PostgreSQL(only takes a couple lines), and then check out how it all works. It will ultimately save you LOTS of headaches, and database can be anywhere, ssl or not.

 

HTH!

Share this post


Link to post
Share on other sites

First you have to turn on SSL support in the postgresql.conf configuration file.

 

Then it depends on your library of choice to use from php.

I use the standard libpq default if you compile PHP with postgresql support.

 

The pg_connect function supports the connection to a Postgresql SSL ready server.

Just look at the parameter option about the SSL:

 

connection_string

The connection_string can be empty to use all default parameters, or it can contain one or more parameter settings separated by whitespace. Each parameter setting is in the form keyword = value. Spaces around the equal sign are optional. To write an empty value or a value containing spaces, surround it with single quotes, e.g., keyword = 'a value'. Single quotes and backslashes within the value must be escaped with a backslash, i.e., \' and \\.

 

The currently recognized parameter keywords are: host, hostaddr, port, dbname, user, password, connect_timeout, options, tty (ignored), sslmode, requiressl (deprecated in favor of sslmode), and service. Which of these arguments exist depends on your PostgreSQL version.

 

Andrew - DBA for [a href=\"http://www.PriceComparison.com\" target=\"_blank\"]http://www.PriceComparison.com[/a]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.