Click to See Complete Forum and Search --> : php /w postgresql
it's my first try with php and postgresql so bear with me. i'm trying to connect my php script to a database and i get this error when i try to run it in a browser:
Fatal error: Call to undefined function: pg_connect() in /home/www/facture/data.php on line 6
any ideas:
here's the script:
<html>
<body>
<?php
$db = pg_connect("dbname=facture user=karinne");
$query = "select * from clients";
$result = pg_exec($db, $query);
if (!$result) {printf ("ERROR"); exit;}
$row = pg_fetch_row ($result,0);
printf ("Compagnie : %s<br>\n", $row[0]);
printf ("Nom : %s<br>\n", $row[1]);
printf ("Prenom : %s<br>\n", $row[2]);
pg_close($db);
?>
</body>
</html>
any help would be appreciated!
EscapeCharacter
09-07-2001, 11:02 AM
looks to me like you didnt build php with postgres support
ok here's what i got if i do a info_php in my script:
'../configure' '--prefix=/usr' '--with-apxs=/usr/bin/apxs' '--with-regex=system' '--with-config-file-path=/etc/php4/apache' '--enable-calendar' '--with-db' '--without-dom' '--enable-filepro' '--enable-ftp' '--with-gettext' '--enable-sysvsem' '--enable-sysvshm' '--enable-track-vars' '--enable-trans-sid' '--disable-debug' '--disable-static' '--with-gd=shared' '--with-imap=shared' '--with-ldap=shared,/usr' '--with-mm' '--with-mhash=shared' '--with-mysql=shared,/usr' '--with-regex=system' '--with-pcre-regex=/usr' '--with-pgsql=shared,/usr' '--with-snmp=shared' '--enable-sockets' '--with-ttf' '--enable-freetype-4bit-antialias-hack' '--with-t1lib' '--with-xml=shared,/usr' '--with-yp' '--with-zlib'
now... i'm running debian (potato) and i saw somewhere that i should add dl('pgsql.so') in my script so here's what my script looks like now:
<html>
<body>
<?php
dl('apache/pgsql.so');
$conn = pg_Connect ("dbname=facture");
$query = "select * from clients";
$result = pg_Exec($conn, $query);
if (!$result) {printf ("ERROR"); exit;}
$row = pg_fetch_row ($result,0);
printf ("Compagnie : %s<br>\n", $row[0]);
printf ("Nom : %s<br>\n", $row[1]);
printf ("Prenom : %s<br>\n", $row[2]);
pg_close($conn);
?>
</body>
</html>
and here's the new error message:
Warning: Unable to load dynamic library '$(prefix)/lib/php4/apache/pgsql.so' - $(prefix)/lib/php4/apache/pgsql.so: cannot open shared object file: No such file or directory in /home/www/facture/data.php on line 6
Fatal error: Call to undefined function: pg_connect() in /home/www/facture/data.php on line 7
common people... somebody's got to know this :(
btw... i installed php4 with dselect (apt-get)
Sweede
09-07-2001, 02:32 PM
just because you installed php4 with debian doesnt mean you can use postgresQL
apt-get install php4-pgsql
causs you know, debian is like that.
r00t619
09-07-2001, 02:37 PM
[k]
Come on now it is telling you the problem in the Error Mesg.
Warning: Unable to load dynamic library '$(prefix)/lib/php4/apache/pgsql.so' - $(prefix)/lib/php4/apache/pgsql.so: cannot open shared object file: No such file or directory in /home/www/facture/data.php on line 6
So from your configure options you set $prefix as /usr so if you go to /usr/lib/php4/apache check to see if you have the file pqsql.so because it is telling you it is not there and that is where it wants it. So find where that file is and cp -pf it there and you should be fine.
At least your running Debian :-)
Debian/Rules!!
Originally posted by r00t619:
So from your configure options you set $prefix as /usr so if you go to /usr/lib/php4/apache check to see if you have the file pqsql.so because it is telling you it is not there and that is where it wants it. So find where that file is and cp -pf it there and you should be fine.
pgsql.so IS in /usr/lib/php4/apache/
now what?!?
jcrowe
09-10-2001, 08:44 AM
I would do what Sweede Said. If that doesn't work (it didn't work for me) I would compile from source. Check out apache toolbox on freshmeat or google. It's definatly the easyest way to compile it correctly.