0

I am trying to connect to a postgreSQL db with the following code.

<?php
    error_reporting(-1);
    $dbh = new PDO('pgsql:dbname=southpark;host=localhost', 'jaseem' , 'DBPassword');
    var_dump( $dbh );
?>

It quits with an error message object(PDO)#1 (0) { }

How do i solve this issue ? Where did i go wrong ? Apache ? postgreSQL ? or php ?

1
  • object(PDO)#1 (0) { } is NOT an error message, it's effectively a visual representation of a PDO object by var_dump. Commented Aug 26, 2011 at 20:59

1 Answer 1

1

That's not an error - you're getting a PDO object. If the PDO instantiation failed, it'd thrown an error and not do the var_dump. If there was some other error, you can check $dbh->errorCode() and $dbh->errorInfo() for details.

Sign up to request clarification or add additional context in comments.

9 Comments

So.. there's no error, you've got a PDO object as expected. Try to run a query.
@jaseem: then, how can you tell it does not work as expected ? All signs seem to indicate you are actually connected to postgre.
resource(2) of type (pgsql link persistent) on 'pg_pconnect("host=$global_host port=$global_port dbname=$global_dbname user=$global_user password=$global_password");'
Yes, that's expected. Your PDO connection is working. So what exactly is your problem? because as things stand right now, your code is working exactly as it should be.
But im not getiing data out of it ! how can i get the output of 'select * from users' ?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.