Thread: BUG #2364: DB Error: connect failed ... PHP/PostgreSql
The following bug has been logged online: Bug reference: 2364 Logged by: manashi Email address: manashi_130582@rediffmail.com PostgreSQL version: psql (PostgreSQ Operating system: Linux Description: DB Error: connect failed ... PHP/PostgreSql Details: hi... I am working on PHP using postgreSQl as DB... Both r very new to me.... i logged in as root and created a user root the command i hav used : createuser root and database sample : createdb sample then to check list of database i used command : psql -l the RESULT was List of databases Name | Owner | Encoding -----------+----------+---------- sample | root | UNICODE template0 | postgres | UNICODE template1 | postgres | UNICODE (3 rows) then i created a table in DB sample name "login" using normal sql query and inserted two datas i created file "show.php" to display the content on web page the code is as follows :- <?php include("DB.php"); $username = "root"; $password = ""; $hostname = "localhost"; $dbname = "sample"; $dsn = "pgsql://$username:$password@$hostname/$dbname"; echo "The DSN : $dsn<br>"; $con = DB::connect($dsn); echo "The Connection Object : $con<br>"; if(DB::isError($con)) { $valu = DB::isError($con); echo "Error Number : $valu <br>"; $val1 = $con->getMessage($valu); echo "The Message : $val1<br>"; } else { echo "Connection established <br>"; } $sql="SELECT id,name FROM login"; echo "$sql<br>"; echo "$rs = $con->query($sql);"; echo "$rs<br>"; if(DB::isError($rs)) { die($rs->getMessage()); } while($row = $rs->fetchRow(DB_FETCHMODE_ASSOC)) { $fulid = $row['id']." "; $fulname = $row['name']." "; echo "Details : $fulid $fulname<br>"; } $con->disconnect(); ?> i created a directory name example in /var/www/html and saved show.php there.... when i am executing this file as http://localhost/example/show.php its displaying : The DSN : pgsql://root:@localhost/sample The Connection Object : Object id #2 Error Number : 1 The Message : DB Error: connect failed SQL QUERY : SELECT id,name FROM login i hav tried a lot to find out the error but unable to find it PostgreSQL version installed in my system : psql (PostgreSQL) 8.0.3 contains support for command-line editing PHP version installed in my system : PHP 5.0.4 (cli) (built: May 9 2005 11:21:11) Copyright (c) 1997-2004 The PHP Group Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies Operating System : LINUX Waiting for the REply...
manashi wrote: > The following bug has been logged online: > > Bug reference: 2364 > Logged by: manashi > Email address: manashi_130582@rediffmail.com > PostgreSQL version: psql (PostgreSQ > Operating system: Linux > Description: DB Error: connect failed ... PHP/PostgreSql This is probably *not* a bug in PostgreSQL, and you'll be able to find better help at the pgsql-general/pgsql-novice/pgsql-php mailing lists. However... > $dsn = "pgsql://$username:$password@$hostname/$dbname"; > echo "The DSN : $dsn<br>"; > > $con = DB::connect($dsn); > The DSN : pgsql://root:@localhost/sample > The Connection Object : Object id #2 > Error Number : 1 > The Message : DB Error: connect failed > i hav tried a lot to find out the error but unable to find it Well: 1. Are you logging connection attempts on the server-side and what does it show? 2. Have you tried turning error verbosity up? 3. What does "psql -U root -h localhost sample" do for you? 4. Have you checked your pg_hba.conf file It's almost certainly an issue with #4 - the pg_hba.conf file. -- Richard Huxton Archonet Ltd
I fail to see how this is a bug, but... Are you running the webserver as root? Most systems don't do that (for good reason!). You should turn on log_connections and log_disconnections in postgresql.conf and see what it shows is happening (you might need to turn up log_min_messages). On Mar 30, 2006, at 1:08 PM, manashi wrote: > > The following bug has been logged online: > > Bug reference: 2364 > Logged by: manashi > Email address: manashi_130582@rediffmail.com > PostgreSQL version: psql (PostgreSQ > Operating system: Linux > Description: DB Error: connect failed ... PHP/PostgreSql > Details: > > hi... > I am working on PHP using postgreSQl as DB... > Both r very new to me.... > i logged in as root and > created a user root > the command i hav used : createuser root > and > database sample : createdb sample > then to check list of database i used command : psql -l > the RESULT was > > List of databases > Name | Owner | Encoding > -----------+----------+---------- > sample | root | UNICODE > template0 | postgres | UNICODE > template1 | postgres | UNICODE > (3 rows) > > then i created a table in DB sample name "login" > > using normal sql query and inserted two datas > > i created file "show.php" to display the content on web page > the code is as follows :- > > <?php > include("DB.php"); > > $username = "root"; > $password = ""; > $hostname = "localhost"; > $dbname = "sample"; > > $dsn = "pgsql://$username:$password@$hostname/$dbname"; > echo "The DSN : $dsn<br>"; > > $con = DB::connect($dsn); > echo "The Connection Object : $con<br>"; > > if(DB::isError($con)) > { > $valu = DB::isError($con); > echo "Error Number : $valu <br>"; > > $val1 = $con->getMessage($valu); > echo "The Message : $val1<br>"; > } > else > { > echo "Connection established <br>"; > } > > $sql="SELECT id,name FROM login"; > echo "$sql<br>"; > > echo "$rs = $con->query($sql);"; > echo "$rs<br>"; > > if(DB::isError($rs)) > { > die($rs->getMessage()); > } > > while($row = $rs->fetchRow(DB_FETCHMODE_ASSOC)) > { > $fulid = $row['id']." "; > $fulname = $row['name']." "; > echo "Details : $fulid $fulname<br>"; > } > $con->disconnect(); > ?> > > i created a directory name example in /var/www/html > and saved show.php there.... > > when i am executing this file as > > http://localhost/example/show.php > > its displaying : > > The DSN : pgsql://root:@localhost/sample > The Connection Object : Object id #2 > Error Number : 1 > The Message : DB Error: connect failed > SQL QUERY : SELECT id,name FROM login > > i hav tried a lot to find out the error but unable to find it > > PostgreSQL version installed in my system : > psql (PostgreSQL) 8.0.3 > contains support for command-line editing > > PHP version installed in my system : > PHP 5.0.4 (cli) (built: May 9 2005 11:21:11) > Copyright (c) 1997-2004 The PHP Group > Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies > > Operating System : LINUX > > Waiting for the REply... > > ---------------------------(end of > broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match > -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461