2
I need to create a connection to a database (already existing) in Postgresql (up and running), using this code (which also existed).
Access file_bd.php
<?php
function conecta() {
$ip = $_SERVER['SERVER_ADDR'];
$acesso = "host=127.0.0.1 dbname=meubanco user=meuuser password=minhasenha port=5432";
$bd = pg_pconnect($acesso);
return $bd;
}
In my file index.php
I call this file and together the method conecta
, it shows the message Fatal error: Call to undefined function pg_pconnect()
.
Procedures Performed
I downloaded php.ini(from the PHP folder) and took the line as a comment extension= php_pgsql.dll
, I also checked that the php_pgsql.dll file is in the referenced ppelo extension_dir folder - extension_dir = "c:/wamp/bin/php/php5.5.12/ext/"
. I copied the file php_pgsql.dll
to the folder apache\bin
. To
Amendment httpd.conf
Added the line as indicated by Anthony Accioly. Loadfile "C:/Program Files/Postgresql/9.3/bin/libpq.dll"
Error message
index php.
Warning: pg_connect(): in C:\wamp\www\testebd\acesso_bd.php on line 8
Call Stack
# Time Memory Function Location
1 0.0000 237520 {main}( ) ..\index.php:0
2 0.0010 241064 conecta( ) ..\index.php:3
3 0.0010 241248 pg_connect ( ) ..\acesso_bd.php:8
That one acesso_bd.php:8
is $bd = pg_pconnect($acesso);
and index.php:3
is $dadosConexao = conecta();
.
phpinfo()
pdo_pgsql
PDO Driver for PostgreSQL enabled
PostgreSQL(libpq) Version 9.2.2
Module version 1.0.2
Revision $Id$
pgsql
PostgreSQL Support |enabled
PostgreSQL(libpq) Version 9.2.2
PostgreSQL(libpq) Uninitialized version string (win32)
Multibyte character support enabled
SSL support disabled
Active Persistent Links 0
Active Links 0
Directive |Local Value | Master Value
pgsql.allow_persistent On On
pgsql.auto_reset_persistent Off Off
pgsql.ignore_notice Off Off
pgsql.log_notice Off Off
pgsql.max_links Unlimited Unlimited
pgsql.max_persistent Unlimited Unlimited
Did you restart the server after uncommenting the line? Another thing, if you are running PHP as a module copy the
php_pgsql.dll
to the folderapache\bin
(see http://stackoverflow.com/questions/7438059/fatal-error-call-to-undefined-function-pg-connect (in English))– Anthony Accioly
Post the relevant entries of
phpinfo()
. See also if open the filelibpq.dll
(in the[diretório de instalação do seu PostgreSQL]\bin\libpq.dll
) help. Example, in thehttpd.conf
include the lineLoadFile "C:/Program Files/PostgreSQL/8.4/bin/libpq.dll"
(source: http://stackoverflow.com/questions/551734/php-not-loading-php-pgsql-dll-on-windows (in English)).– Anthony Accioly
It seems that the wamp also comes with the
libpq.dll
inbin\php\php5.5.12\libpq.dll
(if you don’t have PHP installed locally).– Anthony Accioly
@Anthonyaccioly What part of phpinfo() should I copy ?
– Allan Ramos
All lines related to Postgresql modules (and your Warning too, I think you cut it in half).
– Anthony Accioly
It is mandatory that it be
pg_pconnect
, can’t bepg_connect
? In the PHP documentation there are some notes, where the first one says that some functions may not work in some compilations... Notes. Try thepg_connect
.– KaduAmaral
@Kaduamaral I’m using the
pg_pconnect
because it’s the standard script that company people usually use, but I switched it withpg_connect
and the error remained the same.– Allan Ramos
Alan, there’s still something missing from that warning of yours (like a
Unable to connect 
to PostgreSQL server
or something like that). Apparently the driver is working as it should now, it’s just a matter of seeing what’s stopping you from connecting (whether it’s the connection string or some Postgresql security parameterization).– Anthony Accioly
@AnthonyAccioly https://imagizer.imageshack.us/v2/606x250q90/743/7RqZMI.jpg
– Allan Ramos
There is nothing else in the log navigating to
pg_connect
? Try opening php bug tap as well (Reported here: http://stackoverflow.com/a/6575502/664577).– Anthony Accioly
@Anthonyaccioly left my index.php like this:
require_once('acesso_bd.php');
$dadosConexao = conecta();
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
The message has not changed at all.– Allan Ramos
Put the controls inside the
acesso_bd
.– Anthony Accioly
@Anthonyaccioly I put after the Return. It gave in the same :(.
– Allan Ramos
Let’s go continue this discussão in chat.
– Anthony Accioly