1

I ran a PHP server with postgresql on my college computers which works fine, however on my local machine (which runs MacOS), I get the following error message:

Call to undefined function pg_Connect() in /Users/mac/Documents/<... the remaining path to php file>.php on line 2

Now, I thought it's an issue of missing the postgresql packages for php, so I used brew to install the php postgresql packages. I ran the following commands:

brew install postgresql
brew install php55 --with-postgresql
brew install php55-pdo-pgsql

However, even after running these commands I get the same error when running the php server, i.e.

Call to undefined function pg_Connect() in /Users/mac/Documents/<... the remaining path to php file>.php on line 2

The php version I have is 5.5.30:

mac$ php -v
PHP 5.5.30 (cli) (built: Oct 23 2015 17:21:45) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

Please could you suggest what I am doing wrong to install the packages. I read on stack overflow that the packages can be installed with an apt-get command on linux, however I'm not sure as to what the solution is with the Mac operating system.

Thanks in advance.

3
  • Please run postgres -V command and check your posgress version. If postgress installed correctly then it will show you the version number and details. Commented Mar 27, 2018 at 10:07
  • Hi, thanks for the reply. I think postgres is installed correctly but I can't access it via php, e.g. I can't use functions such as pg_connect() from php. Commented Mar 27, 2018 at 10:38
  • I get the following output from postgres -V: postgres (PostgreSQL) 10.3 Commented Mar 27, 2018 at 10:38

1 Answer 1

1

The solution was edit the php.ini on your server then find this below line and uncomment that line.

extension="pgsql.so"

then restart the server apache and test it out again.

Also, check this link for the steps regarding installation of the postgress to mac OS.

Sign up to request clarification or add additional context in comments.

5 Comments

Hi, thanks for the quick reply. I checked the php.ini file (under /etc directory) and could not find the line: extension="pgsql.so". However the following lines were present: extension=php_pdo_pgsql.dll and extension=php_pgsql.dll. I uncommented both of these and restarted the server (I'm running local server) and tried again but it did not work. Any possible reasons for this?
i get the following output: postgres (PostgreSQL) 10.3
I just checked the link you gave (thanks for that), I am able to view the postgres tables from the command line as mentioned in the link, however I think the problem is with accessing postgres via PHP. I'm not completely sure though.
Ok then might be that will be the problem because postgress is fine in your case. Please upvote/accept my answer if that helpful to you. Thanks. @AmishBedi
Ok, thanks I'll try to figure out what's wrong. Thanks for helping out anyway!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.