Link to home
Start Free TrialLog in
Avatar of ivanovn
ivanovnFlag for United States of America

asked on

PEAR and PostgreSQL

I have PHP 5.1.1 and I installed PEAR 1.4.9. Then I installed the DB 1.7.6 package to use with an application that would be accessing the PostgreSQL 8.1 database. This is all on Windows XP Pro.

However, when I run the application it does everything correctly, but when it comes to the part where it's supposed to connect to the datbase I get the following error:
DB Error: extension not found

I uncommented the php_pgsql.dll extension, and I set the extension_dir in php.ini. I restarted the Apache and I still get the same error.

What could be the issue?

Thanks.
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you show us your code?
Avatar of ivanovn

ASKER

Yes, the relevant database connection file is:

<?php

require_once 'DB.php'; //PEAR DB package

class DBConnection
{
      function DSN()
      {
            $db_engine = 'pgsql';
            $db_user = '<username>';
            $db_pass = '<password>';
            $db_host = '<ipaddress>';
            $db_port = '5432';
            $db_name = '<dbname>';

            $datasource = $db_engine.'://'.
             $db_user.':'.
            $db_pass.'@'.
             $db_host.':'.$db_port.'/'.
              $db_name;              
            return $datasource;
      }
      
      function GetDBConnection()
      {
            $datasource = DBConnection::DSN();
              $db_obj =& DB::connect($datasource, TRUE);

              if(DB::isError($db_obj))
            {
                  echo "Not Connecting To the DataBase. Please Try Again.". $db_obj->getUserInfo();
                  exit;
            }

            $db_obj->setFetchMode(DB_FETCHMODE_ASSOC);
                        
            return $db_obj;
      }
}
?>

The error is coming from the if(DB::isError($db_obj)) branch.
And all the credentials are correct? Can you try a quick test using standard calls rather than PEAR DB?

Avatar of ivanovn

ASKER

Yes, I checked the credentials and I can make a connection using standard calls rather than PEAR DB.
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ivanovn

ASKER

Ok, I figured out what the issue was. My php.ini file was in system32 and for some reason php kept looking for it in Windows directory. So none of the php.ini changes were implemented when restarting the Apache. Once I moved the file and enabled pgsql module everything worked.

Thanks for the help.
OOI. Did the code I provide make any difference?

Create info.php as <?php phpinfo(); ?>

Run that through your browser and look for "Configuration File".
Avatar of ivanovn

ASKER

I did not attempt the code you gave me.

I did create a file with phpinfo() and that's how I figured out the php.ini was not in a right place.
Ok. You got it working anyway. Sorry I could get there more directly.

Well done and thanks for the points.