can't connect to postgresql database in PHP code

I have a postgresql database which I can connect to via the PhpStorm IDE. However, when I try to access it from PHP code, I get the error 'could not find driver'. My code follows the pattern of a simple 'how to' page from W3Schools - I would paste the URL but you seem to have disabled paste in this editor.

The key command is a call to create a new PDO object, passing it the URI which works for the IDE (which starts with 'jdbc:postgresql://[server hostname]:5432/[database]'). The SQL is a call which works fine interactively.

1 comment
Comment actions Permalink

In case anyone's interested/in the same boat:

One of the many documents I have found on the web states that JDBC is only for Java database connectivity. Presumably it is used from PhpStorm because that is a Java program. Accessing the same Postgres database from a PHP script requires a different protocol.

I have just tried using the pgsql: driver (having first enabled the php_pdo_pgsql and php_pgsql extensions in my php.ini file). This driver has a different syntax from jdbc:postgresql. Using it, I have managed to run my query successfully.


Please sign in to leave a comment.