Solved

PEAR and PostgreSQL

Posted on 2006-07-13
9
470 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
  • 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

821 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