PDA

View Full Version : PHP with postgres support


rudar
02-04-2002, 01:27 PM
I'm trying to set my iBook (500 running 10.1.2) as a web server so I can teach myself more stuff. Right now I have the stock apache running and postgres 7.1.3 installed. I've tried re-building PHP a couple of times using the --with-pgsql option, both with PHP 4.0.6 and 4.1.1. I don't get any compile errors, and the standard php test script works fine. But when trying to run a simple postgres query in a php script, I get a fatal error saying pg_connect is an undefined function...

Any hints?

W3iRd0
02-04-2002, 01:39 PM
Took a look at the php manual (can't remember where I got it) and found this:


A connection to PostgreSQL server can be established with the following value pairs set in the command string: $conn = pg_connect("host=myHost port=myPort tty=myTTY options=myOptions dbname=myDB user=myUser password=myPassword ");

The previous syntax of: $conn = pg_connect ("host", "port", "options", "tty", "dbname") has been deprecated.

Hopefully this helps...

Edit: Same comp, same system, MySQL, REALLY easy...

rudar
02-04-2002, 01:45 PM
Thanks, but I don't think that's the problem. The test script is :
<html>
<body>

<h1>Gleefully Served by Mac OS X</h1>
<?php
$db=pg_connect("dbname=test user=postgres");
$query="select * from names";
$result=pg_exec($db, $query);
if (!$result) {printf ("ERROR"); exit;}
echo $result;
pg_close($db);
?>
</body>
</html>

And the error message:

Fatal error: Call to undefined function: pg_connect() in /Library/WebServer/Documents/index.php on line 6

So I don't think it's taking exception to the form of the arguments (or to there not being as many of them as suggested), but that it seems to think I haven't yet installed pgsql support so it can't find the function.

Unless there's some command to import the modules before it can use them? But I didn't see anything like that in the docs I found about how to do this...

Gwyrrdin
02-05-2002, 06:34 AM
Did you specify the path to your postgresql headers?

like

./configure --with-pgsql=/usr/local/path-to/pgsql.h

I know that for mysql you can use both with the configure script.
If you just give the --with-mysql option it will use a generic mysql library.
But if you specify the path, it will use YOUR headers and libraries...

That could make the difference...


cheers

Gwyrrdin

rudar
02-06-2002, 03:50 PM
Thanks, gwyrrdin. This might help pinpoint things. I had assumed a default install of postgres would leave everything in its default locations. Whereas it seems that I do not have a pgsql.h file in /usr/local/pgsql/, or anywhere else for that matter. Are you sure that's the right file name to be looking for? If so I guess I'll have to try re-compiling postgres, which I'm _really_ not looking forward to...