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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP and PostgreSQL: pg_connect problem 1

Status
Not open for further replies.

gwinn7

Programmer
Feb 10, 2001
1,004
US
Has anyone here developed or is developing a PHP project against a PostgreSQL database? If so...

Can you explain or help me resolve this problem:

When I try to use the pg_connect() function in a PHP page, an error occurs:

"Call to Undefined Function"

This error is triggered when I step through the PHP code and land on this line...

$connection = pg_connect("test");

What does this mean? How can I resolve it?

Thanks in advance,
Gary
gwinn7
 
OK, I commented the requested non-PHP4 lines and restarted Apache. The problem is still there.

I back tracked a little bit to see if I had any other potential concerns, but I didn't find any. I checked the PHP script I used. The phpinfo function on another page displays properly. So, it is actually processing PHP code. I also verified that Postgres was running in the background.

If this is helpful to you here is the exact error message...

"Fatal error: Call to undefined function: pg_connect() in /var/ on line 12"

What other items should we check?

Gary
gwinn7

Memorable lines...

"Spock, help me... Spock." -- Star Trek, James Kirk era.

"Sir, I have to take the mains off the line..its...rad iation." -- Star Trek II, Wrath of Khan.

"Scotty, I need warp speed in three minutes or we're all dead." -- Star Trek II, Wrath of Khan.
 
Did you comment out the following also?
Code:
<IfDefine HAVE_PHP>
LoadModule php_module         modules/mod_php.so
</IfDefine>

Also, the real question: are you sure Apache is loading the PHP module, or is it possible that PHP is already statically compiled into Apache? Try commenting out ALL lines relating to PHP in httpd.conf, and then restart Apache and see if PHP still runs. If so, then THAT's the problem.

Whatever the case, we will carry this thing through until you have what you want. I haven't been defeated by PHP yet ;-). -------------------------------------------

&quot;Calculus is just the meaningless manipulation of higher symbols&quot;
                          -unknown F student
 
No, I did not comment those lines. I will try that and experiment with restarting Apache with all lines commented. Actually, I really don't know if PHP is already statically compiled into Apache. I only installed the Red Hat binaries, mostly.

Thanks again for your continued help in this issue! I will let you know tomorrow morning when I am back in the office.


Gary
gwinn7
 
Trial 1:

Commented ALL PHP related lines and restarted Apache.

RESULT: PHP code would not process (ie. no output from Apache through a browser)

Trial 2:

Commented <IfDefine HAVE_PHP> block of code, left the remaining PHP4 entries enabled, then restarted Apache.

RESULT: Same error as original issue. The pg_connect still does not process and is considered an undefined function.

Well, it appears that PHP was not compiled into Apache. The entries in the httpd.conf do seem to have a critical affect in loading PHP support as you stated.

I am ready for the next step. Any ideas?

Gary
gwinn7
 
OK, let me ask:

When you run the phpinfo() script, search through the outputted web page for any reference to &quot;pgsql&quot;. There should be a very small section with the heading &quot;pgsql&quot; and which confirms that PostgreSQL support is enabled.

And more importantly, I notice a quote from one of your previous posts:

&quot;OK, I just downloaded the source files for PHP. If you want, we could compile the PHP source.

Do I need to uninstall my old PHP installation first?&quot;

It is not necessary to uninstall IF you are sure that your compiled version of PHP will replace the existing PHP object files. But it is usually best practice to uninstall first, rather than trust the system to do it for you. Usually in these cases, when compiling a fresh PHP, the files get placed in a different directory, and thus do not really replace the old installation of PHP.

Do a full system search for the file &quot;libphp4.so&quot;, and see if it shows up in more than one place. -------------------------------------------

&quot;Calculus is just the meaningless manipulation of higher symbols&quot;
                          -unknown F student
 
OK, I will have answers to those questions posted Monday morning.

Gary
gwinn7
 
Ok, it appears that pgsql is not in the header. There is a section that outlines compilation options, titled &quot;Configure Command&quot;. There is no option with pgsql. Here is a copy of that section...

'./configure' 'i386-redhat-linux' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--prefix=/usr' '--with-config-file-path=/etc' '--disable-debug' '--enable-pic' '--disable-rpath' '--enable-inline-optimization' '--with-apxs=/usr/sbin/apxs' '--with-bz2' '--with-curl' '--with-db3' '--with-dom' '--with-exec-dir=/usr/bin' '--with-gd' '--with-gdbm' '--with-gettext' '--with-jpeg-dir=/usr' '--with-mm' '--with-openssl' '--with-png' '--with-regex=system' '--with-ttf' '--with-zlib' '--with-layout=GNU' '--enable-debugger' '--enable-ftp' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-track-vars' '--enable-yp' '--enable-wddx' '--without-mysql' '--without-unixODBC' '--without-oracle' '--without-oci8' '--with-pspell' '--with-xml'

This is very strange because, I did compile PHP 4 using the &quot;--with-pgsql=&quot; option. When I installed it from compiling it, I did the following:

1. Ran &quot;./configure --with-pgsql=/usr&quot;
2. Ran &quot;make&quot;
3. Ran &quot;make install&quot;
4. Done. Restarted Apache

Furthermore, the libphp4.so file is in the &quot;/usr/lib/apache&quot; folder. There is only one copy of this in the entire file system.

My thinking at this point is to completely uninstall PHP4 and Apache. Then, recompile/install PHP4 with the pgsql option, then compile/reinstall Apache. Before I only installed Apache from the RPMs.

Ready for more instructions! :)

Gary
gwinn7
 
Well, I can tell you this much: that is NOT the version of PHP that you compiled. If you simply did --with-pgsql and left everything else as default, there is no way you would have ended up with the info above. PHP defaults to /usr/local, and the one you quote above has --prefix=/usr (actually it has that in there twice, of all things)

So, another .so file for PHP has to be on your system somewhere.

'Furthermore, the libphp4.so file is in the &quot;/usr/lib/apache&quot; folder.'

Well, I noticed that the httpd.conf file was looking for a module inside the 'modules' folder. Did you look in there? Did you do the search as 'root'? (otherwise you might not find everything). You could try specifying the complete path &quot;/usr/local/apache&quot; in the LoadModule statement.

If this were my system, though, I would be tempted to do a complete reinstall, with only the core developer libraries, and then build Apache, PostgreSQL and PHP from source. There is a reason Unix systems still stick to this old method, and it is called &quot;flexibility&quot;. (sheesh...) And while you're at it, you might want to reconsider RedHat as your Linux distribution of choice. For my money, Slackware sticks much more closely to the Unix conventions, and leaves you much more choice in system configuration.

Of course, my ultimate recommendation is FreeBSD, if you really want a rock-solid system that gives you complete control, but it does take a little more RTFM-ing to learn the system. -------------------------------------------

&quot;Calculus is just the meaningless manipulation of higher symbols&quot;
                          -unknown F student
 
OK. It sounds like we have gone as far as we can with this and the tools to solve this problem are all laid out in front of me. I will have to back-track and see if I can resolve this thing. I will let you know how it went.

Thanks again for your input and I will put it to good use and get this thing working somehow.

Gary
gwinn7
 
SOLVED!

Issue resolved. Solution was the syntax of the AddType directive.

AddType application/x-httpd-php .php .phtml

was..

AddType application/x-httpd-php4 .php .phtml


That's it!

Gary
gwinn7
 
Good 4 you. Isn't it funny how one small character can make all the difference?

I hope you enjoy working with PostgreSQL. It has quickly become my favorite database. Come visit the PostgreSQL forum (forum699 ) whenever you have questions or issues in development.

Also, note that PHP is coming up with all kinds of cool new features for PostgreSQL support, such as table-to-array, array-to-table, etc... When these new features get ironed out, PHP/PostgreSQL is going to be THE solution.

Regards. -------------------------------------------

&quot;Now, this might cause some discomfort...&quot;
(
 
Thanks Rycamor!

Gary
gwinn7
A+, Network+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top