1

I have been trying PHP + nginx on windows, well everythng worked fine until I had to use postgres.

Error:

Fatal error: Call to undefined function pg_connect() in C:\nginx\html\main.php on line 15

Whenevr I try initiating a postgres connection this happens.

I checked and there is nothing wrong on line 15(or before or after). I know this as I have specially downloaded and installed WAMP with postgres as database everything works fine.

2
  • you haven't enabled pg in php, so the pg functions aren't loaded. Commented Jul 13, 2015 at 14:21
  • what do you get back if run phpinfo() from an HTML file? Commented Jul 13, 2015 at 14:23

1 Answer 1

2
  • Take a look at the output of phpinfo(). It tells you which php.ini file has been used.
  • Open that file in an editor.
  • Search for the extension_dir=... parameter; it should point to a directory on your machine.
  • Take a look in that directory and check whether there is a php_pgsql.dll.
  • Back in the php.ini check whether there is a extension=php_pgsql.dll parameter.
  • If there is a leading semi-colon before that line, remove it (; marks a comment).
  • If the line is missing, add it.
  • Restart the webserver/apache.
  • Check whether phpinfo() prints the postgres section.
Sign up to request clarification or add additional context in comments.

2 Comments

Had to set extension_dir = "C:\nginx\php\ext" as I had moved php inside nginx folder. Also had to start php using "start /b c:\nginx\php\php-cgi.exe -b 127.0.0.1:9000 -c c:\nginx\php\php.ini" as the "Loaded Configuration File" option was showing "none"
Works with nginx indeed even if php has not been compiled with pgsql.

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.