Call to undefined function pg_Connect() Error

Posted January 3, 2017 28k views
ApachePHPPostgreSQLUbuntu 16.04

DigitalOcean support team couldnt solve this issue. i ve Ubuntu 16.04 with php7, apache2, PostgreSQL v9.5 and im running php code to read data form PostgreSQL from my 2nd server.

here is the code php

but im getting Call to undefined function pgConnect() in /home/f****/publichtml/.****.net/new.php on line 11

php -i result:

i tried like every possible soluitons but no luck. im open to all solutions
i can give u server access if u really needed

Please help

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers


Try installing this: apt-get install php5-pgsql
And also check your command is pg_connect all lower case.

Make sure you restart apache afterwards.

If that’s still failing afterwards perhaps add the port to your connection string,



  • @michaelbrandl

    If he’s using PHP 7.x and opts to install php5-pgsql, then the package manager will install PHP 5.x and associated packages which won’t be available to PHP 7.x since they will install to and use two different directories.


The actual function is pg_connect not pg_Connect (you’re using a C instead of c in the function name).

The function should look like the following:

pg_connect("host=host_ip port=5432 dbname=db_name user=db_user password=db_pass");

Did you ever figure it out, I’ve got the same problem using same snippet of PHP