Posted on October 15th, 2011 No comments
This is a recurring problem i had. For some reason (which i later found out), i couldnt get my php scripts to connect to postgresql. The scripts borked at, for example, pg_connect() (unable to find the function, blah blah).
First off, usually php doesnt come configured to run the postgresql dll out of the box (the windows extension is commented), so you have to uncomment it yourselves.
In php.ini, uncomment (remove the “;”) the following line:
so it becomes
Still, when i restarted Apache, i got the error:
“Unable to load dynamic library ‘c:\Programs\PHP\ext\php_pgsql.dll’”
Which was intriguing since the dll was where it was supposed to be.
As it turns out, on later versions of php, the dll is linked to “libpq.dll”, a postgresql dll. So, to fix things, i added the following line to httpd.conf:
(replace the path to your postgresql installation dir, of course – and be careful copying the line above because of the “)
this way the dll is preloaded when apache is started and we dont get the “Unable to link…” error.
This was tested with xampp on windows xp pro, with apache 2.2.17, php 5.3.5 and postgresql 9.0. Other versions can probably affect the solution presented.
PS – On some situations (probably php versions), it is needed to replace the php_pgsql.dll file that comes with php with one from a previous version. This wasnt necessary on my case.
Heres a useful link from where i got the info:
http://php.net/manual/pt_BR/install.windows.apache2.php (see the comments)
Ran into the same problem, but this time on windows 7 64bit. I was using XAMPP 1.7.7 (Apache 2.2.21 / PHP 5.3.8) and postgresql 9.1 64bit.
- I uncommented the php_pgsql.dll in php.ini, restarted apache and got an error.
- Added the loadfile line (see above) to httpd.conf and the apache service couldnt start.
No matter what i did, nothing worked. After a few hours of head banging, i had the bright idea of searching for the 64bit part on the postgresql install and i found this article:
(in case you dont want to read, it says, in a nutshell: you are safe using the 32bit version of postgresql on a 64bit OS)
So i thought the problem might be from just that. Heres what i did:
- Installed the 32bit version of postgresql 9.1
- Added the loadfile line to httpd.conf.
- Restarted the apache service…and it worked.
So we end up with: Windows 7 Ultimate 64bit + XAMPP 1.7.7 + PostgreSQL 9.1 32bit + Smile