読者です 読者をやめる 読者になる 読者になる

PHP Fatal error: Call to a member function prepare() on a non-object

データベースの接続がうまくいってないのが原因です。

試しで下の接続方法で接続してみた。

$link = pg_connect("host=localhost dbname=db user=usr password=pass");

FATAL: Ident authentication failed for use 'hoge_user' が出ました。

postgresqlがうまく動いているかを確認してみるのがいいと思います。

再起動してみる

#su - postgres

-bash-4.1$pg_ctl start -w

あれれ

pg_ctl: another server might be running; trying to start server anyway
waiting for server to start....2016-02-14 14:00:00 GMT [4244]LOG: could not bind IPv4 socket: Address already in use
2016-02-14 14:00:00 GMT [4244]HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2016-02-14 14:00:00 GMT [4244]LOG: could not bind IPv6 socket: Address already in use
2016-02-14 14:00:00 GMT [4244]HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2016-02-14 14:00:00 GMT [4244]WARNING: could not create listen socket for "*"
2016-02-14 14:00:00 GMT [4244]FATAL: could not create any TCP/IP sockets
.... stopped waiting
pg_ctl: could not start server
Examine the log output

起動失敗

-bash-4.1$ lsof -i:5432

-bash-4.1$ kill PID

再度起動(よっうまくいった)

接続みてみたら治った。よかった