Dipro Sen
Dipro Sen

Reputation: 4670

PostgreSql 'PDOException' with message 'could not find driver'

pdo is working fine with mysql but with pgsql its giving error 'PDOException' with message 'could not find driver' I've installed php5-pgsql package which also includes pdo_pgsql

http://packages.debian.org/sid/php5-pgsql

This package provides a module for PostgreSQL database connections directly from PHP scripts. It also includes the pdo_pgsql module for use with the PHP Data Object extension.

my dsn is pgsql:dbname=DB;host=192.168.0.2 I am using Ubuntu 10.04

Upvotes: 49

Views: 139638

Answers (11)

Dan Darrow
Dan Darrow

Reputation: 1

using Amazon ec2 linux 2 (redhat ?); PHP from Apache would not find driver but it was there on command line (psql) After spending an inordinate amount of time checking config files, out of desperation, I rebooted the ec2 server instance- and problem solved (just like windows :) as dogbert tech support once said "shut up and reboot"

Upvotes: 0

user15404850
user15404850

Reputation: 11

Just run php --ini and look for Loaded Configuration File in output for the location of php.ini used by your CLI

then check you have enabled the extensions correctly.

Upvotes: 1

hakuna_matata
hakuna_matata

Reputation: 123

I had the same problem with another solution. I lost my around 4 hours to solve this problem. Please check the following to solve this problem.

  1. Check php.ini file and remove semicolon from this line

    extension=pgsql

    extension=pdo_pgsql

  2. Restart your apache2 server

    sudo service apache2 restart

  3. Check if your PDO driver has updated in localhost phpinfo()

enter image description here

I did All the things right and still I had this problem. And you know why? Because I had several versions of php installed. So I was running php7.4 in my php cli but localhost was running on php7.2. So always check your php versions.

  1. Check your php version on localhost and terminal cli

enter image description here

Upvotes: 3

Goms
Goms

Reputation: 2644

This message means you need to install and or activate postgresql extension in PHP

This solution works for me : To install postgresql extension

[sudo] apt-get install php-pgsql

after, for activating it, uncomment pgsql and pdo-pgsql extensions in etc/php/$PHP_VERSION/apache2/php.ini file

enter image description here

Finally, type :

[sudo] /etc/init.d/apache2 restart

To restart apache server if you use apache such as was my case...

Upvotes: 68

Braian Coronel
Braian Coronel

Reputation: 22867

When you do not have postgresql installed on the same machine that is Apache and PHP; you have to install php-pgsql and don't have to add extensions in php.ini manually in Linux (in Windows yes), because redundancies are generated and this does not work (checked in error.log).

$ sudo apt install php-pgsql

Then you can check the existence of the extension enabled automatically in:

$ sudo nano /etc/php/7.0/apache2/conf.d/10-pdo.ini

Observations: In phpinfo() you will find the directory conf.d/ and the file error.log

GL

Upvotes: 2

Rafael Matsumoto
Rafael Matsumoto

Reputation: 71

Try to remove semicolon in front of

extension=pgsql
extension=pgsql.so

included in your php.ini file

You can do that from the XAMPP Control Panel.

enter image description here

Upvotes: 4

Amir Md Amiruzzaman
Amir Md Amiruzzaman

Reputation: 2079

Here is what I did to solve the problem.

  1. Edit php.ini and remove ; from extension=pdo_pgsql. Also, add extension=pgsql.so to the php.ini file.

  2. Make sure to restart the Apache server before you try to see the result.

Upvotes: 3

Gabriel Kniznik
Gabriel Kniznik

Reputation: 63

Copy libpq.dll from the PHP directory to Apache24\bin (or wherever your installation could be).

Upvotes: -4

Maxim Klakov
Maxim Klakov

Reputation: 61

I had the same issue. First of all - check is it enabled in php.ini. Uncomment extension=php_pdo_pgsql...

than set up extension directory!!

extension_dir = "ext" ; for your case it could be other dir.

and do not forget to restart server after changing the config.

Upvotes: 4

Jan Marek
Jan Marek

Reputation: 11180

1) Have you enabled pgsql.so in php.ini (extension=pgsql.so)?

2) Is you Postgresql listenin on 192.168.0.2 interface? (You can check it by netstat -tpln)

3) How you authenticate your access into Postgresql?

Upvotes: 22

newenglander
newenglander

Reputation: 2049

Make sure you've uncommented the line that tells php where the Postgres driver is (usually extension=pgsql.so) in the main php.ini file.

Upvotes: 9

Related Questions