Solved

PEAR and PostgreSQL

Posted on 2006-07-13
9
456 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:RQuadling
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:RQuadling
ID: 17108153
And all the credentials are correct? Can you try a quick test using standard calls rather than PEAR DB?

0
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 40

Accepted Solution

by:
RQuadling 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:RQuadling
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:RQuadling
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now