Author Topic: Getting fatal errors for pg_ functions  (Read 2309 times)

0 Members and 1 Guest are viewing this topic.

Offline akarinTopic starter

  • Irregular
  • Posts: 3
    • View Profile
Getting fatal errors for pg_ functions
« on: March 15, 2010, 05:06:01 AM »
Hi,
I've been having trouble getting php to work with postgresql.
While I can do things like pg_connect, pg_query, pg_fetch_assoc with out any problems, a number of pg_ functions such as pg_affected_rows, pg_cmdtuples, pg_escape_string are returning Fatal error: call to undefined function.

What could be the cause?

I'm using
php 5.2.13 (built from source)
apache 2.2.15 (built from source)
postgres 8.4.2 (linux installer)

thanks!

Offline btherl

  • Guru
  • Fanatic
  • *
  • Posts: 3,791
  • Gender: Male
  • Matt is the best!
    • View Profile
Re: Getting fatal errors for pg_ functions
« Reply #1 on: March 15, 2010, 08:38:00 AM »
Can you post the code?
Your php questions answered at Flingbits

Offline akarinTopic starter

  • Irregular
  • Posts: 3
    • View Profile
Re: Getting fatal errors for pg_ functions
« Reply #2 on: March 15, 2010, 08:02:30 PM »
Some code from a small test file I'm testing with
echo pg_escape_string("A-B'C");
returns
Quote
Fatal error: Call to undefined function pg_escape_string() in /usr/local/apache/htdocs/test.php on line

        $db pg_connect('host=localhost dbname=db1 user=pgadmin password=admin');

        
$query "SELECT * FROM student";

        
$result pg_query($query);
        if (!
$result) {
            echo 
"Problem with query " $query "<br/>";
            echo 
pg_last_error();
            exit();
        }
	
$op pg_affected_rows($result);
	
$op pg_cmdtuples($result);
	
echo 
"<TABLE>";
        while(
$myrow pg_fetch_assoc($result)) {
            
printf ("<tr><td>%s</td><td>%s</td><td>%s</td></tr>"$myrow['id'], htmlspecialchars($myrow['program']), htmlspecialchars($myrow['stage']));
        }

	
echo 
"</table>";

if I comment out the pg_affected_rows and  pg_cmdtuple lines then the code works fine.

Offline btherl

  • Guru
  • Fanatic
  • *
  • Posts: 3,791
  • Gender: Male
  • Matt is the best!
    • View Profile
Re: Getting fatal errors for pg_ functions
« Reply #3 on: March 15, 2010, 09:59:02 PM »
Well that is very strange.  those functions have been around since php 4.2.0 apparently, so it's not a php version issue.  I wonder though if there's a mismatch somewhere between the versions you've got installed, or perhaps they weren't integrated properly.  Building from source is not simple, especially for building php so that it can work properly with apache.

If you just need things to work, I would go with the pre-packaged versions of everything.  If your objective is to learn by building from source and have plenty of free time, then you're in for a ride :)
Your php questions answered at Flingbits

Offline akarinTopic starter

  • Irregular
  • Posts: 3
    • View Profile
Re: Getting fatal errors for pg_ functions
« Reply #4 on: March 15, 2010, 10:49:16 PM »
thanks btherl.
I'm guessing there might be some dependencies missing and so the php wasn't installed properly with pgsql support.
At first I used the postgres installer it failed to complete the installation. I added manually some of the lib files when I was building from source. Now I uninstalled the postgres and run the installer again. This time is runs fine and I was able to install the pre-packaged apachephp. Finally it works!