1
2

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.

XAMPを使ってPHPでPostgreSQLにアクセスする際の諸注意

Posted at

XAMPを使ってPHPを動かしているのですが、PostgreSQLに接続しようとしたところでエラーに陥ったので共有です。
すごい初歩的なノウハウで大変恐縮ですが何かしらの参考になれば幸いです。

まず、PDOでPostgreSQLに接続しようとした際に以下のようなコードを記述しました

//接続するデータベースの情報
$dsn = 'pgsql:dbname=test host=localhost port=5432';
$user = 'posgre';
$password= 'posgre';

//データベースへの接続開始
try{
    $dbh = new PDO($dsn, $user, $password);
    print ('接続成功');
//データベースへの接続に失敗した場合
}catch(PDOException $e){
    print ('接続失敗:' .$e -> getMessage());
    die();
}

PODでDBに接続する設定はおかしなところはないと思うのですが、could not find driverというエラーが出力されました。

調べてみたところ、php.iniに設定されている.dllファイルを読み込む設定のところで、
php_pdo_pgsql.dllのセミコロンを取り除かなければならないようです。

変更前
;extension=php_pdo_pgsql.dll

変更後
extension=php_pdo_pgsql.dll

変更後はApacheを再起動することもお忘れなきよう。(数分間これで悩んでしまいました・・・。)

参考
PDOでPostgreSQLにつなぐときのエラー
http://fmfmfm.hatenablog.com/entry/2012/05/01/115642

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?