[pgsql-jp: 28748] Re: qmail経由で起動した PHP からDBアクセス

HOTTA Michihide hotta @ net-newbie.com
2003年 1月 24日 (金) 10:33:46 JST


堀田@諫早市です。

On Fri, 24 Jan 2003 09:50:31 +0900
"mots" <angel @ cosmos-inc.net> wrote:

> 次のパターンで接続を試みました。
> 
> #dbnameのみ
> $pgcstr  = 'dbname=mt2';
> #古い指定方法で(カンマ区切り)
> //$pgcstr  = 'host="",port=5432, dbname=mt2, user=postgres';
> #現行の指定方法で(スペース区切り)
> //$pgcstr  = 'host="" port=5432 dbname=mt2 user=postgres';
> //$pgcstr  = 'host="" port=5432 dbname=mt2 user=mots';
> //$pgcstr  = 'host="" port=5432 dbname=mt2 user=mots password="xxxxxx"';
> //$pgcstr  = 'host="" port=5432 dbname=mt2 user=www password="xxxxxx"';

画面にエラーメッセージは表示されませんでしたか?
手元の環境ではこうなりました。

$ tail -2 /var/lib/pgsql/data/pg_hba.conf
local  all    all                                      trust
host   all    all    127.0.0.1       255.255.255.255   trust

$ grep tcpip /var/lib/pgsql/data/postgresql.conf
#tcpip_socket = false

$ cat b.php
<?php
function    my_pg_connect($db)  {
    printf("=== connecting: %s\n", $db);
    if ($con = pg_connect($db)) {
        printf("ok\n");
        pg_close($con);
    }
}
my_pg_connect('dbname=hotta');
my_pg_connect('host="" port=5432 dbname=hotta user=hotta');
my_pg_connect('host="localhost" port=5432 dbname=hotta user=hotta');
my_pg_connect('dbname=hotta user=hotta');

$ php -q b.php (出力中の HTML のタグはカットしました)
=== connecting: dbname=hotta
ok
=== connecting: host="" port=5432 dbname=hotta user=hotta
pg_connect() unable to connect to PostgreSQL server: 
 unknown host name: ""  in /home/httpd/html/b.php on line 4
=== connecting: host="localhost" port=5432 dbname=hotta user=hotta
pg_connect() unable to connect to PostgreSQL server: 
 unknown host name: "localhost" in /home/httpd/html/b.php on line 4
=== connecting: dbname=hotta user=hotta
ok

host や port を指定する場合は、それなりの設定を行う必要があります。
詳細は、以下を参照してください。

http://search.net-newbie.com/pgsql/client-authentication.html
http://search.net-newbie.com/pgsql/runtime-config.html

# 'unknown host name' というのも、わかりにくいメッセージですね。
# 'connection refused' くらいがいいような気がします。
-- 
HOTTA Michihide <hotta @ net-newbie.com> <http://www.net-newbie.com>



pgsql-jp メーリングリストの案内