PEAR and PostgreSQL

Posted on 2006-07-13
Last Modified: 2013-12-12
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?

Question by:ivanovn
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 40

Expert Comment

by:Richard Quadling
ID: 17106706
Can you show us your code?
LVL 10

Author Comment

ID: 17107832
Yes, the relevant database connection file is:


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.'://'.
            return $datasource;
      function GetDBConnection()
            $datasource = DBConnection::DSN();
              $db_obj =& DB::connect($datasource, TRUE);

                  echo "Not Connecting To the DataBase. Please Try Again.". $db_obj->getUserInfo();

            return $db_obj;

The error is coming from the if(DB::isError($db_obj)) branch.
LVL 40

Expert Comment

by:Richard Quadling
ID: 17108153
And all the credentials are correct? Can you try a quick test using standard calls rather than PEAR DB?

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

LVL 10

Author Comment

ID: 17108211
Yes, I checked the credentials and I can make a connection using standard calls rather than PEAR DB.
LVL 40

Accepted Solution

Richard Quadling earned 500 total points
ID: 17115551
I did see this on

"This package been superseded by MDB2 but is still maintained for bugs and security fixes."

Try this ...

In your DB/pgsql.php, at around line 276, you should see the lines ...

        $ini = ini_get('track_errors');
        $php_errormsg = '';
        if ($ini) {

Just before

if ($ini) {


echo '<pre>' . var_export($connect_function, True) . var_export($params, True) . '</pre>';

I suspect that you are returning a supplying a string and not an array as required by the connect method. See the soure's docblock ...

    * @param array $dsn         the data source name

So, try this as your DSN() function (more or less - you may need to edit it).

function DSN()
      return array
//            'connect_timeout' => ,
            'database' => '<dbname>',
//            'dbsyntax' => ,
            'hostspec' => '<ipaddress>',
            'new_link' => false,
//            'options' => ,
            'password' => '<password>',
            'port' => 5432,
            'protocol' => 'tcp',
//            'service' => ,
//            'socket' => ,
//            'sslmode' => ,
//            'tty' => ,
            'username' => '<username>',

The commented-out lines are optional. I just read the source and supplied them all.

LVL 10

Author Comment

ID: 17129935
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.
LVL 40

Expert Comment

by:Richard Quadling
ID: 17129947
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".
LVL 10

Author Comment

ID: 17130038
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.
LVL 40

Expert Comment

by:Richard Quadling
ID: 17130044
Ok. You got it working anyway. Sorry I could get there more directly.

Well done and thanks for the points.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question