Menu

How to enable PostgreSQL extension for PHP?

Few days ago, I started a new project. This project was required to be built with PHP and PostgreSQL database. Docker is really cool for all infrastructure things, it makes my life much easier to bootstrap a project in other computers/servers.

I am crazy about new frameworks and I heard very good feedback from my friend about Phalcon PHP framework, so I decided to choose Phalcon. I started my project from archetype with official Phalcon-Compose (link) project. Ok, it was easy and after couple of minutes I started integration with database.

PostgreSQL support is not available by default PHP installation. You should turn it on by yourself. There are 2 ways, it depends on your project implementation, how are you going to deal with database integration:

  • PDO API – offers a nice interface, which supports about 12 different DB drivers.
  • PGSQL – this API supports only PostgreSQL.

Solution

To enable the PostgreSQL PHP extension you need to add the following line to the php.ini file of your running PHP version:

extension=pgsql.so

 

To enable the PostgreSQL PDO Extension, you need to add the following line to the php.ini file:

extension=pdo_pgsql.so

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *