akarin Posted March 15, 2010 Share Posted March 15, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/195283-getting-fatal-errors-for-pg_-functions/ Share on other sites More sharing options...
btherl Posted March 15, 2010 Share Posted March 15, 2010 Can you post the code? Quote Link to comment https://forums.phpfreaks.com/topic/195283-getting-fatal-errors-for-pg_-functions/#findComment-1026322 Share on other sites More sharing options...
akarin Posted March 16, 2010 Author Share Posted March 16, 2010 Some code from a small test file I'm testing with echo pg_escape_string("A-B'C"); returns 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. Quote Link to comment https://forums.phpfreaks.com/topic/195283-getting-fatal-errors-for-pg_-functions/#findComment-1026711 Share on other sites More sharing options...
btherl Posted March 16, 2010 Share Posted March 16, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/195283-getting-fatal-errors-for-pg_-functions/#findComment-1026761 Share on other sites More sharing options...
akarin Posted March 16, 2010 Author Share Posted March 16, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/195283-getting-fatal-errors-for-pg_-functions/#findComment-1026771 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.