Discussion:
[PHP] Undefined function pg_connect()
(too old to reply)
Gustavo Amarilla Santacruz
15 years ago
Permalink
Hello, all.

I had installed php + postgresql on Fedora12. When the php script call to
"pg_connect()", the following message is displayed:

Fatal error: Call to undefined function pg_connect() in /var/www/html/ .....
Call Stack: 0.0325 487160 1. {main}() ....


What i can do?


Thank you, in advance.


-------------------------
Gustavo Amarilla
Chris
15 years ago
Permalink
Post by Gustavo Amarilla Santacruz
Hello, all.
I had installed php + postgresql on Fedora12. When the php script call
Fatal error: Call to undefined function pg_connect() in /var/www/html/
..... Call Stack: 0.0325 487160 1. {main}() ....
What i can do?
You need the php-pgsql package if you installed via rpm.

Once you have that installed, restart apache and see how you go.
--
Postgresql & php tutorials
http://www.designmagick.com/
--
Sent via pgsql-php mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php
Devrim GÜNDÜZ
15 years ago
Permalink
Post by Gustavo Amarilla Santacruz
I had installed php + postgresql on Fedora12. When the php script call
Fatal error: Call to undefined function pg_connect()
If you are installing from RPMs, you also need to install php-pgsql
package. If you are installing from sources, you will need to recompile
with PostgreSQL support.
--
Devrim GÜNDÜZ, RHCE
Command Prompt - http://www.CommandPrompt.com
devrim~gunduz.org, devrim~PostgreSQL.org, devrim.gunduz~linux.org.tr
http://www.gunduz.org Twitter: http://twitter.com/devrimgunduz
--
Sent via pgsql-php mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php
Gustavo Amarilla Santacruz
15 years ago
Permalink
Thank you, Chris.

I use the yum command and i got the following result:

yum install php-pgsql
Loaded plugins: presto, refresh-packagekit
Setting up Install Process
Package php-pgsql-5.3.1-1.fc12.i686 already installed and latest version
Nothing to do


What i can do?

Thank you, in advance.
Post by Chris
Post by Gustavo Amarilla Santacruz
Hello, all.
I had installed php + postgresql on Fedora12. When the php script call to
Fatal error: Call to undefined function pg_connect() in /var/www/html/
..... Call Stack: 0.0325 487160 1. {main}() ....
What i can do?
You need the php-pgsql package if you installed via rpm.
Once you have that installed, restart apache and see how you go.
--
Postgresql & php tutorials
http://www.designmagick.com/
---------------------------
Gustavo Amarilla
Bill Moran
15 years ago
Permalink
Post by Gustavo Amarilla Santacruz
Thank you, Chris.
yum install php-pgsql
Loaded plugins: presto, refresh-packagekit
Setting up Install Process
Package php-pgsql-5.3.1-1.fc12.i686 already installed and latest version
Nothing to do
Have you restarted Apache since it was successfully installed?
--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/
--
Sent via pgsql-php mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php
Gustavo Amarilla Santacruz
15 years ago
Permalink
Thank you, Bill Moran.

My httpd is stoped, for default.

I used the command: service httpd start; then, the following message was
displayed:

Starting httpd: [Thu Jan 28 20:27:39 2010] [warn] module perl_module is
already loaded, skipping
[Thu Jan 28 20:27:39 2010] [warn] module php5_module is already loaded,
skipping
httpd: Could not reliably determine the server's fully qualified domain
name, using localhost.localdomain for ServerName
[ OK ]


But the pg_connect function is not recognized.
Post by Bill Moran
Post by Gustavo Amarilla Santacruz
Thank you, Chris.
yum install php-pgsql
Loaded plugins: presto, refresh-packagekit
Setting up Install Process
Package php-pgsql-5.3.1-1.fc12.i686 already installed and latest version
Nothing to do
Have you restarted Apache since it was successfully installed?
--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/<http://people.collaborativefusion.com/%7Ewmoran/>
--
Gustavo Amarilla

¿Reciclaste papel, hoy?
Chris
15 years ago
Permalink
...
Does a phpinfo() page show it loading anything re: pgsql ?

Anything in apache logs (/var/log/httpd/error.log probably) ?

Could seLinux be involved somehow (I'm not really sure where to look for
this, something in /var/log should have some info) ?


On your phpinfo page, it should have something like this:

Configuration File (php.ini) Path /etc/php.ini
Scan this dir for additional .ini files /etc/php.d


Check whether the rpm put a file in that extra directory, like:

# cat /etc/php.d/pgsql.ini
; Enable pgsql extension module
extension=pgsql.so

If it didn't, try doing it manually (and restart httpd) and see if pgsql
shows up in your phpinfo page now.
--
Postgresql & php tutorials
http://www.designmagick.com/
--
Sent via pgsql-php mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php
Gustavo Amarilla Santacruz
15 years ago
Permalink
...
Thank you, Chris



*1) Does a phpinfo() page show it loading anything re: pgsql ?*

No, no matter info on pgsql.


*2) Anything in apache logs (/var/log/httpd/error.log probably) ?*

Yes, i found this:

.
.
.
PHP Warning: PHP Startup: Unable to load dynamic library
'./;/usr/lib/php/modules/;/usr/lib/pgsql/curl.so' -
./;/usr/lib/php/modules/;/usr/lib/pgsql/curl.so: cannot open shared object
file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'./;/usr/lib/php/modules/;/usr/lib/pgsql/fileinfo.so' -
./;/usr/lib/php/modules/;/usr/lib/pgsql/fileinfo.so: cannot open shared
object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'./;/usr/lib/php/modules/;/usr/lib/pgsql/json.so' -
./;/usr/lib/php/modules/;/usr/lib/pgsql/json.so: cannot open shared object
file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'./;/usr/lib/php/modules/;/usr/lib/pgsql/ldap.so' -
./;/usr/lib/php/modules/;/usr/lib/pgsql/ldap.so: cannot open shared object
file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'./;/usr/lib/php/modules/;/usr/lib/pgsql/mysql.so' -
./;/usr/lib/php/modules/;/usr/lib/pgsql/mysql.so: cannot open shared object
file: No such file or directory in Unknown on line 0
.
.
.


*
3) On your phpinfo page, it should have something like this:

Configuration File (php.ini) Path /etc/php.ini
Scan this dir for additional .ini files /etc/php.d

*
Yes, the phpinfo page has this information.

*
4) Check whether the rpm put a file in that extra directory, like:

# cat /etc/php.d/pgsql.ini
; Enable pgsql extension module
extension=pgsql.so*


Yes, the rpm put that file in /etc/php.d




----------------------------
Gustavo Amarilla
Gustavo Amarilla Santacruz
15 years ago
Permalink
On Fri, Jan 29, 2010 at 10:07 PM, Gustavo Amarilla Santacruz <
...
I commented the php.ini line in the extension_dir parameter:

*Before:*
.
.
.
; Directory in which the loadable extensions (modules) reside.
; http://www.php.net/manual/en/ini.core.php#ini.extension-dir
; extension_dir = "./"
extension_dir = "./;/usr/lib/php/modules/;/usr/lib/pgsql/"
.
.
.


*After:*
.
.
.
; Directory in which the loadable extensions (modules) reside.
; http://www.php.net/manual/en/ini.core.php#ini.extension-dir
; extension_dir = "./"
;extension_dir = "./;/usr/lib/php/modules/;/usr/lib/pgsql/"
.
.
.


Then, a new message was displayed:

"Warning: pg_connect(): Unable to connect to PostgreSQL server: could not
connect to server: Permission denied Is the server running on host
"localhost" and accepting TCP/IP connections on port 5432? could not connect
to server: Permission denied Is the server running on host "localhost" and
accepting TCP/IP connections on port 5432?"




The pg_hba.conf file containt:




# TYPE DATABASE USER CIDR-ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1 255.255.255.0 trust
# IPv6 local connections:
host all all ::1/128 ident



What i can do?

Thank you, in advance.


--------------------------
Gustavo Amarilla
Raymond O'Donnell
15 years ago
Permalink
Post by Gustavo Amarilla Santacruz
"Warning: pg_connect(): Unable to connect to PostgreSQL server: could
not connect to server: Permission denied Is the server running on host
"localhost" and accepting TCP/IP connections on port 5432? could not
connect to server: Permission denied Is the server running on host
"localhost" and accepting TCP/IP connections on port 5432?"
Sounds like you're getting somewhere - the PG extension is being found now.

The error above is nothing to do with pg_hba.conf; if the connection was
being denied because of a rule there, the error would say so explicitly.
Rather, it's a network problem of some kind. Is the server actually
running? Is there a firewall preventing access?

Ray.
--
Raymond O'Donnell :: Galway :: Ireland
***@iol.ie
--
Sent via pgsql-php mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php
Chris
15 years ago
Permalink
Post by Gustavo Amarilla Santacruz
; Directory in which the loadable extensions (modules) reside.
; http://www.php.net/manual/en/ini.core.php#ini.extension-dir
; extension_dir = "./"
;extension_dir = "./;/usr/lib/php/modules/;/usr/lib/pgsql/"
These should be colon separated, not semicolon - notice it's trying to
load both paths included:

PHP Warning: PHP Startup: Unable to load dynamic library
'./;/usr/lib/php/modules/;/usr/lib/pgsql/curl.so'

Change it to

extension_dir = "./:/usr/lib/php/modules/:/usr/lib/pgsql/"
Post by Gustavo Amarilla Santacruz
"Warning: pg_connect(): Unable to connect to PostgreSQL server: could
not connect to server: Permission denied Is the server running on host
"localhost" and accepting TCP/IP connections on port 5432? could not
connect to server: Permission denied Is the server running on host
"localhost" and accepting TCP/IP connections on port 5432?"
"Permission denied" sounds like either file permissions or seLinux is
stopping the connection.

If you have seLinux enabled, try disabling it (don't know how to do
that, sorry) - at least that will tell you if that's the problem.

For file permissions, check your apache user can read where-ever the
postgres socket file is put (normally /tmp/.s.PGSQL.5432 on centos/rhel).
--
Postgresql & php tutorials
http://www.designmagick.com/
--
Sent via pgsql-php mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php
Gustavo Amarilla Santacruz
15 years ago
Permalink
Thank you, all.

I had access to the SELinux->Boolean; next, i check the option:

"Allow HTTPD scripts and modules to connect to databases over the network".



Then, a new message was displayed:

Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: Ident
authentication failed for user "gestock" .......


I can login with gestock data (user/password) through the postgresql psql
tool. But from apache i can not.

Note: the php.ini file was not modified.
...
--
Gustavo Amarilla
Chris
15 years ago
Permalink
Post by Gustavo Amarilla Santacruz
Thank you, all.
"Allow HTTPD scripts and modules to connect to databases over the
network".
Ident authentication failed for user "gestock" .......
I can login with gestock data (user/password) through the postgresql
psql tool. But from apache i can not.
It's not using the password, it's just checking the username to see if
you're logged in as 'gestock' (but 'apache' is not 'gestock', hence the
error).

What does your postgresql pg_hba.conf file look like?
--
Postgresql & php tutorials
http://www.designmagick.com/
--
Sent via pgsql-php mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php
Gustavo Amarilla Santacruz
15 years ago
Permalink
Thank you, Chris.

The pg_hba.conf contained:

# TYPE DATABASE USER CIDR-ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1 255.255.255.0 trust
# IPv6 local connections:
host all all ::1/128 ident


Before, i modified to:

# TYPE DATABASE USER CIDR-ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1 255.255.255.0 trust
# IPv6 local connections:
host all all ::1/128 trust


Then i can login me. But, how i Know that apache is using IPV6 connections?
...
--
Gustavo Amarilla

¿Reciclaste papel, hoy?
Gustavo Amarilla Santacruz
15 years ago
Permalink
I am sorry. Please, ommit the previous post.

The correct post is the following:


Thank you, Chris.

The pg_hba.conf file contained this:

# TYPE DATABASE USER CIDR-ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1 255.255.255.0 trust
# IPv6 local connections:
host all all ::1/128 ident


After, i modified it to:

# TYPE DATABASE USER CIDR-ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1 255.255.255.0 trust
# IPv6 local connections:
host all all ::1/128 trust


Then i can login me from php scripts. But, how i Know that apache is using
IPV6 connections?

On Mon, Feb 1, 2010 at 9:51 PM, Gustavo Amarilla Santacruz <
...
--
Gustavo Amarilla

¿Reciclaste papel, hoy?
Loading...