LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-12-2003, 01:14 PM   #1
peteABK
Member
 
Registered: May 2003
Location: Canada
Distribution: Fedora 13
Posts: 49

Rep: Reputation: 15
Postgresql and PHP problem


I'm trying to make my first PHP / database page (basically out of bordom) but I'm having some trouble connecting to the psql. I've been searching for a while but all I've come up with is the pg_connect( string dbname) function. When I try to run the page I get an error stating that the function is undefined. Any tips are appreciated.
 
Old 06-26-2003, 03:54 PM   #2
MArgRes
Member
 
Registered: Jun 2003
Distribution: Fedora Core 2
Posts: 37

Rep: Reputation: 15
Here is a snippet that just tests whether you can connect or not. I'm assuming that you have all of the relevant software installed -- php, apache, mod_php, php-pgsql, postgres, etc.

Code:
<?php
        $conn = pg_connect('user=<user-name> dbname=<database-name>');
        if (!$conn)
        {
                echo "Connection failed!";
        }
        else
        {
                echo "Connection succeeded!!!";
        }
?>
If that doesn't work, post the error message(s)...
 
Old 06-28-2003, 11:34 PM   #3
leed_25
Member
 
Registered: Jul 2002
Location: san francisco
Distribution: freebsd
Posts: 102

Rep: Reputation: 17
Re: Postgresql and PHP problem

Quote:
Originally posted by peteABK
[. . .] When I try to run the page I get an error stating that the function is undefined. Any tips are appreciated.
when you compiled php did you remember to include this option

--with-pgsql

don't know? put this

phpinfo();

as the first executable statement of your script.
 
Old 06-29-2003, 10:51 PM   #4
peteABK
Member
 
Registered: May 2003
Location: Canada
Distribution: Fedora 13
Posts: 49

Original Poster
Rep: Reputation: 15
I would like to thank both of you for your replies.

MArgRes, I've tried your snippet thank you, but I still get:

Call to undefined function: pg_connect() /home/user/directory/file.php

leed_25, I also want to say thanks, I'm just trying to use the version of php that came with RH9, should I download another and recompile it in? I ran phpinfo() and I couldn't find anything in ther about postresql or mysql.
 
Old 06-30-2003, 10:43 AM   #5
MArgRes
Member
 
Registered: Jun 2003
Distribution: Fedora Core 2
Posts: 37

Rep: Reputation: 15
Okay, you probably didn't install the php-pgsql package. This is needed to run the Postgresql stuff from PHP. What you need to do is install it with RPM. It's on the third disc of Redhat 9. Put the disc in, and install the package with this command:

rpm -Uvh php-pgsql-4.2.2-8.0.5.i386.rpm

Once that's done, try to run the code I gave you again...
 
Old 07-24-2003, 03:01 AM   #6
abd_bela
Member
 
Registered: Dec 2002
Location: algeria
Distribution: redhat 7.3, debian lenny
Posts: 627

Rep: Reputation: 31
Hi,
I have the same problem as our friend peteABK
Ive installed php-pgsql, php

I try exactly the script proposed by MArgRes , this is the error

Warning: pg_connect() unable to connect to PostgreSQL server: FATAL 1: IDENT authentication failed for user "bela" in /home/bela/public_html/bdEtud/index.php on line 3
Connection failed!


while rhe connection is correct on the xterm:
psql -U bela etudiant
Welcome to psql, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit

etudiant=# \q

thanking for answer
bela
 
Old 07-24-2003, 03:20 AM   #7
abd_bela
Member
 
Registered: Dec 2002
Location: algeria
Distribution: redhat 7.3, debian lenny
Posts: 627

Rep: Reputation: 31
perhaps the answer ih here:

how to connect to user database bela for instance if jour are login in the unix as bela ??
look at these 2 examples:


[jijel@info-50 jijel]$ psql -U bela etudiant -W
Password:
psql: FATAL 1: IDENT authentication failed for user "bela"

here from jijel login : error ( passwd is correct )

[jijel@info-50 jijel]$ su - bela
Password:

login as bela


[bela@info-50 bela]$ psql -U bela etudiant -W
Password:
Welcome to psql, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit

etudiant=# \q
[bela@info-50 bela]$

From php , you must precise the user ( otherwise you are anonymous )

thanks

bela
 
Old 08-03-2003, 07:44 PM   #8
SandyTipper
LQ Newbie
 
Registered: Aug 2003
Location: Toronto
Distribution: Redhat 9
Posts: 1

Rep: Reputation: 0
As I see it, the problem is "undefined function", not authentication or connection errors.

I have the same problem (RedHat 9).

php-pgsql is installed.
php_info shows '--with-pgsql=shared'
(so recompiling seems unnecessary.)

/etc/php.d/pgsql.ini has in it:
; Enable pgsql extension module
extension=pgsql.so

The following files exist:
/usr/lib/php4/pgsql.so
/usr/lib/pgsql/plpgsql.so

This is a production web site that used to work before upgrading to RH9. HELP!!!!!!!

 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[PHP/POSTGRESQL] Resource id #12? Elijah Programming 1 07-12-2004 03:41 AM
postgresql php insert problem BobNz Linux - General 3 05-19-2004 10:46 PM
php/postgresql BobNz Programming 4 05-10-2004 06:18 PM
Slackware Postgresql and PHP squirreldogger Slackware 2 11-21-2003 05:19 PM
Connect to PostgreSQL via PHP RedHatMN Programming 3 12-12-2002 06:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration