Call to Undefined Function pg_pconnect()

Asked

Viewed 594 times

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 folder apache\bin(see http://stackoverflow.com/questions/7438059/fatal-error-call-to-undefined-function-pg-connect (in English))

  • Post the relevant entries of phpinfo(). See also if open the file libpq.dll (in the [diretório de instalação do seu PostgreSQL]\bin\libpq.dll) help. Example, in the httpd.conf include the line LoadFile "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)).

  • It seems that the wamp also comes with the libpq.dll in bin\php\php5.5.12\libpq.dll (if you don’t have PHP installed locally).

  • @Anthonyaccioly What part of phpinfo() should I copy ?

  • All lines related to Postgresql modules (and your Warning too, I think you cut it in half).

  • It is mandatory that it be pg_pconnect, can’t be pg_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 the pg_connect.

  • @Kaduamaral I’m using the pg_pconnect because it’s the standard script that company people usually use, but I switched it with pg_connect and the error remained the same.

  • Alan, there’s still something missing from that warning of yours (like a Unable to connect &#xA;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).

  • @AnthonyAccioly https://imagizer.imageshack.us/v2/606x250q90/743/7RqZMI.jpg

  • 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).

  • @Anthonyaccioly left my index.php like this: require_once('acesso_bd.php');&#xA;$dadosConexao = conecta();&#xA;ini_set('display_startup_errors',1);&#xA;ini_set('display_errors',1);&#xA;error_reporting(-1); The message has not changed at all.

  • Put the controls inside the acesso_bd.

  • @Anthonyaccioly I put after the Return. It gave in the same :(.

Show 9 more comments

1 answer

1


I talked to the person in charge who gave me the code,: port=5433

Browser other questions tagged

You are not signed in. Login or sign up in order to post.