Pg_escape_string() does not exist after installing php5-pgsql

php
postgresql

#1

We’ve got a PHP app that uses postgres and up until today it’s been passing unit tests just fine. Now when running phpunit we’re getting:

................................................................. 65 / 77 ( 84%)
....PHP Fatal error:  Call to undefined function pg_escape_string() in /home/ubuntu/app/src/Model/Table/appTable.php on line 158

That particular model has not changed, nor has anything in our circle.yml file changed.

We are using Ubuntu 14.04 for the build, and have specified that php5-pgsql needs to be installed in our circle.yml

dependencies:
  post:
    - sudo apt-get update && sudo apt-get install php5-pgsql

The output from the apt-get install command shows that pgsql has been enabled:

Creating config file /etc/php5/mods-available/pgsql.ini with new version
php5_invoke: Enable module pgsql for cli SAPI
php5_invoke: Enable module pgsql for apache2 SAPI

I rebuilt with SSH and was able to see php5-psql installed when running dpkg -l | grep php

Any ideas what might be causing this? Or tips to work around it?

Thanks!


#2

In case anyone else runs into this, the postgres extension for php has vanished from the default setup. Yay, love undocumented, unannounced, sudden changes.

This was hard to debug because our PHP code is using PDO for most things but then pg_escape_string() is used in a few places, and that is only provided by the extension.

Here’s how I was able to fix it:

dependencies:
  post:
      - sudo apt-get update
      - sudo apt-get install php5-pgsql
      - cp /usr/lib/php5/20121212/pgsql.so /opt/circleci/php/5.5.31/lib/php/extensions/no-debug-non-zts-20121212
      - echo 'extension=pgsql.so' > /opt/circleci/php/5.5.31/etc/conf.d/psql.ini

#3