php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8689 pg_Connect() seems to do some type of caching that doesn't quite work
Submitted: 2001-01-13 14:08 UTC Modified: 2001-02-13 12:12 UTC
From: matt at webcraft dot ch Assigned:
Status: Closed Package: PostgreSQL related
PHP Version: 4.0.4pl1 OS: Linux (2.2.7)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: matt at webcraft dot ch
New email:
PHP Version: OS:

 

 [2001-01-13 14:08 UTC] matt at webcraft dot ch
<?
function dummy($x) {

  $database = pg_Connect("dbname=template1 port=5432");
  $querystring = "set datestyle to 'ISO'";
  $result = pg_exec ($database, $querystring);
  
  echo "database = $database <br>";
    
  // note 1: by commenting out the following line the bug disappears
  $x = pg_NumRows($result);
  
  // note 2: by commenting out the following line the bug disappears
  $y = pg_NumRows($result);
  
  // note 3: by un-commenting following line the bug disappears
  // pg_close($database);
  
  return 0;
}

// note 4: if the return-value is ignored by commenting out the following
// line (only the first line: $x =)
$x = 
dummy("12345");

echo "database = $database <br>";

// note 5: a change in the connect-string, like an additional space
// at the end of the connect-string, makes the bug disappear
$database = pg_Connect("dbname=template1 port=5432");
$querystring = "set datestyle to 'ISO'";
$result = pg_exec ($database, $querystring);

echo "database = $database <br>";


?>

Comment:
You can easily reproduce the bug by copy/paste-ing the above code in a file
and check it out in a browser.
By following the instruction in any one (try one at a time!) of the notes 1 to 5 in 
the above source you can get the bug to dissappear, which doesn't make a lot 
of sense in most cases (except from note 3).
It seems to me, that pg_Connect() decides it has that connection already made
(based on a cmpstr() of the two connect-strings), but the database-ressource
has actually gone out of scope (but only under obscure circumstances, see notes...).

Therefore you will get an error like this:

Warning: 1 is not a valid PostgreSQL link resource in /www/auszweiterhand/docs/connect_test.php on line 33

Even though it should be valid at this point.

Thanks for looking into it!

regards
Matt



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-13 12:12 UTC] thies@php.net
believed to be fixed in CVS
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 21:01:31 2025 UTC