Solved

PEAR and PostgreSQL

Posted on 2006-07-13
9
476 Views
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?

Thanks.
0
Comment
Question by:ivanovn
[X]
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
9 Comments
 
LVL 40

Expert Comment

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

Author Comment

by:ivanovn
ID: 17107832
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.
0
 
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?

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

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

Accepted Solution

by:
Richard Quadling earned 500 total points
ID: 17115551
I did see this on http://pear.php.net/package/DB

"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) {

add

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.


0
 
LVL 10

Author Comment

by:ivanovn
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.
0
 
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".
0
 
LVL 10

Author Comment

by:ivanovn
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.
0
 
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.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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 …

751 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