title: Fatal error: Call to undefined function pg_connect()
body: <p>I am trying to connect to my database (remote server) which has PostgreSQL installed in it. My PHP code is trying to connect to the database using pg_connect(), but I get the error saying:- "Fatal error: Call to undefined function pg_connect() in /var/www/website/functions.php on line 82".</p>
  
  <p>The line 82 simply is:</p>
  
  <pre><code>$db = pg_connect($conn_string);
  where $conn_string = "host=".$hostname." port=5432 dbname=".$dbname." user=".$db_user." password=".$db_password.""
  </code></pre>
  
  <p>(all variables defined earlier)</p>
  
  <p>I checked many forums and the only solution suggested was locating the php.ini file which contains a line:- extension = pgsql.so (for UNIX) and extension = php_pgsql.dll (for Windows). </p>
  
  <p>This statement is supposed to be commented and the solution is to uncomment it. I have tried it but still does not change the situation. The remote server has a version later than PostgreSQL v9.0.4 installed. 
  I then installed PostgreSQL v8.4.8 on to my laptop and ran the website locally using MAMP. At first, Apache crashed for some odd reason, I fixed that problem but again I ended up with the same error as before i.e. Fatal error: Call to undefined function pg_connect()....</p>
  
  <p>I also ran the <code>phpinfo()</code> and it showed that the php version does support the PostgreSQL module.I have spent an entire day searching for the solution but have been unsuccessful. This is my first project developing a website and I am out of wits. Any kinda help will be highly appreciated.</p>
  
  <p>phpinfo() gives me a huge list of things at the terminal but the listings relevant to PostgreSQL are as follows:-</p>
  
  <pre><code>pdo_pgsql
  
  PDO Driver for PostgreSQL =&gt; enabled
  PostgreSQL(libpq) Version =&gt; 9.0.4
  Module version =&gt; 1.0.2
  Revision =&gt;  $Id: pdo_pgsql.c 306939 2011-01-01 02:19:59Z felipe $ 
  
  pgsql
  
  PostgreSQL Support =&gt; enabled
  PostgreSQL(libpq) Version =&gt; 9.0.4
  Multibyte character support =&gt; enabled
  SSL support =&gt; enabled
  Active Persistent Links =&gt; 0
  Active Links =&gt; 0
  
  Directive =&gt; Local Value =&gt; Master Value
  pgsql.allow_persistent =&gt; On =&gt; On
  pgsql.auto_reset_persistent =&gt; Off =&gt; Off
  pgsql.ignore_notice =&gt; Off =&gt; Off
  pgsql.log_notice =&gt; Off =&gt; Off
  pgsql.max_links =&gt; Unlimited =&gt; Unlimited
  pgsql.max_persistent =&gt; Unlimited =&gt; Unlimited
  </code></pre>
  
  <p>I had restarted MAMP after every edit I made since it was mentioned in every post I have read so far. I believe that resets both Apache and php.</p>
  
  <p>'pqsql.so' (which is the UNIX equivalent of 'php_pqsql.dll' in Windows) is present in the 'extension' directory. I also copy-pasted the 'pqsql.so' file on to the Apache/bin directory but it did not give me any change.</p>
  
  <p>I am not running php in the command line primarily. I just was curious to see what phpinfo() would give me relevant to pgsql which I have mentioned in my reply above.</p>
  
  <p>I am still working on the tools you have mentioned and will respond as soon as I get any results.</p>
  
  <p>Thanks,
  H</p>