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

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-13 12:12 UTC] thies@php.net
believed to be fixed in CVS
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC