Bug #72544 [Fbk->Opn]: pg_connect using the "service" parameter
| From: | floriparob at gmail dot com | Date: | Wed, 06 Jul 2016 22:09:18 +0000 |
| Subject: | Bug #72544 [Fbk->Opn]: pg_connect using the "service" parameter | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-202111@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72544&edit=1
ID: 72544
User updated by: floriparob at gmail dot com
Reported by: floriparob at gmail dot com
Summary: pg_connect using the "service" parameter
-Status: Feedback
+Status: Open
Type: Bug
Package: PostgreSQL related
Operating System: Debian
PHP Version: 5.6.23
Block user comment: N
Private report: N
New Comment:
The error message is:-
PHP Warning: pg_connect(): Unable to connect to PostgreSQL server: definition of service
"staging" not found
If it were a permissions issue I'd expect to see "cannot stat" etc. as the error
message.
I had a look at the libpq source, in particular fe_connect.c, and it requires the environment
variables PGSERVICE and PGSERVICEFILE in order to connect, obtaining the "key" from
PGSERVICE and then looking up the connect parameters in pg_service.conf whose path is defined in
PGSERVICEFILE. This works with psql.
So how does php5-pgsql set the PGSERVICE environment variable?
Should we upgrade to PHP7?
Previous Comments:
------------------------------------------------------------------------
[2016-07-05 07:29:46] requinix@php.net
It seems to be supported as far as I can tell. What's the error message?
------------------------------------------------------------------------
[2016-07-05 02:19:56] floriparob at gmail dot com
Description:
------------
The documentation for pg_connect says that it recognises the "service" parameter as a
connect string.
In the pg_service.conf file you can have entries for several databases, each with their own distinct
IP addresses, passwords, etc. So, in your PHP code you'd expect to be able to do something like
this wrapped up in a try catch block:-
$connect_string = "service=staging";
$pg_handle = pg_connect($connect_string);
to access the "staging" data base.
With psql you have to do this:-
PGSERVICE=staging;export PGSERVICE
psql
is run without any parameters. It opens the pg_service.conf file and finds the entry defined as
"staging" and from that obtains all the necessary configuration parameters in order to
open a connection to that database.
I tried this:-
putenv("PGSERVICE=staging");
$connect_string = "service=staging";
$pg_handle = pg_connect($connect_string);
but still no luck.
So, if this is not a bug could somebody please enlighten me about the correct way to connect using
pg_service.conf.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72544&edit=1