7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PDOでPostgresSQLを使おうとしたら'could not find driver'というエラーが出た

Last updated at Posted at 2016-01-09

プログラムを実行したところ「PDOのPostgreSQLのドライバーがないよ」というエラーが出ました.

$ php test.php
Error: Uncaught exception 'PDOException' with message 'could not find driver'

##ドライバのインストール
php -i でPostgreSQLがあるかを確認

$ php -i | grep pdo
PHP Warning:  Module 'json' already loaded in Unknown on line 0
/etc/php.d/pdo.ini,
/etc/php.d/pdo_mysql.ini,
/etc/php.d/pdo_sqlite.ini,
PHP Warning:  Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0
pdo_mysql
pdo_mysql.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock
pdo_sqlite

ない.

yum でインストール
(yumパッケージがphpのバージョン(もしくはOSのバージョン)によって異なることがあるようです)

$ yum install php-pdo_pgsql

pg_hbaファイルでlocalhostを許可

localhostの接続を変更していない場合は,以下のように変更します.

$ vi /var/lib/pgsql/9.5/data/pg_hba.conf
# IPv4 local connections:
host    all             all             127.0.0.1/32            peer
# IPv6 local connections:
host    all             all             ::1/128                 ident

localhostを許可するようにします
以下のように変更


# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 md5

これで通りました.

##参考
PostgreSQL(Postgres Toolkit) pg_hba.confファイルの設定 ユーザ”postgres”のIdent認証に失敗しました
Do I have to recompile PHP for adding Postgres PDO support?

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?