Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PEAR and PostgreSQL

Posted on 2006-07-13
9
Medium Priority
?
488 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

824 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