Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connection problem with PostgreSQL

Status
Not open for further replies.

TheSofty

Programmer
Jul 8, 2003
35
IT
Hi all,

I'm an absolute beginner in PHP world. I'm trying to connect to PostgreSQL 7.4.6 on a Fedora 2 box in my LAN through PHP 4.3.10 installed via RPM. The script I'm using runs OK until this line:

Code:
if (!$connect=pg_connect("host=$host port=$port user=$user password=$password dbname=$dbname"))
{
    echo "Couldn't connect!!\n";
}

The values for the vars are:
Code:
$host = "192.168.1.2";   (I tried "localhost", too)
$port = 5432;
$user = "postgres";
$password = "postgres";
$dbname = "tempoweb";

I don't see anything after the connection line, it seems that the remaining code is not executed. I KNOW that PostgreSQL is working because I can connect OK from a Windows box through pgAdmin3, and I can select data from tables there.

Ah, phpinfo() shows '--with-pgsql=shared' in the 'Configure command' area, and PostgreSQL is listed among other DB in the "dbx/Supported databases" area.

Any clue?

TIA

TheSofty
 
Have you checked out pg_last_error($connect)?
Look at what the server had to say.
 
DRJ478,

in /var/log/messages I see:
PHP Fatal error: Call to undefined function: pg_connect() in /var/ in line 14 (that is the line I showed above).

pg_last_error() returns nothing, I mean I can't echo it in any way.

Thanks

TheSofty
 
The message would indicate that the postgre sql was not loaded. Is there a line for the .so in the php.ini?
 
DRJ478,

I searched /etc/php.ini for ".so" and the only reference I found is (note the semicolon);
Code:
;  extension=msql.so
in the "Dynamic Extensions" section.

TheSofty
 
I recall some issues with loading postgre in specific environments.
I'd recommend to try the following:
1. uncomment the .so
2. restart the web server
3. try

If that doesn't work you'll have to load the .so dynamically in the scripts.
 
DRJ478,

excuse my ignorance, but when you write "Uncomment the .so" you mean the msql.so, or another PostgreSQL-specific .so? And in this case, what is its name?

How can I load a .so dinamically in a script?

I tried uncommenting the line I showed you in my last post and restarting my Apache 2.0.51, but I see no change.

Thanks for your patience.

TheSofty
 
Sorry - I didn't see it's mssql. Forget the uncommenting.
However, the PHP manual says:
PostgreSQL module may be loaded using extension directive in php.ini or dl() function.
That means you can add
Code:
extension=pgsql.so
to the php.ini to load the .so
Alternatively you can include in the script
Code:
dl("pgsql.so");
That should dynamically load the extension for PostGRE
 
DRJ478,

OK, the fog is diminishing! But now I do not find pgsql.so anywhere on my Fedora2 box. Is it in a package other than postgresql-7.4.6-2PGDG.rpm (which I used to install)?

TheSofty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top