php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #4230 pg_connect clears environment variables on a second connection establishment
Submitted: 2000-04-24 21:41 UTC Modified: 2000-05-21 18:17 UTC
From: mlemos at acm dot org Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Release Candidate 1 OS: Linux RH 6
Private report: No CVE-ID: None
 [2000-04-24 21:41 UTC] mlemos at acm dot org
When pg_connect is opens a connections that is then closed and pg_connect
is called again to open a connection again important environment variables
like PG_DATESTYLE are cleared and the last connection is set as if that
variable was not set. Try this script to replicate the problem. It doesn't
happen at least in PHP 3.0.14.

<?

Function Connect(&$error)
{
 if(!function_exists("pg_connect"))
 {
  $error="PostgreSQL support is not available in this PHP configuration";
  return(0);
 }
 Putenv("PGUSER=root");
 Putenv("PGPASSWORD=");
 Putenv("PGDATESTYLE=ISO");
 $connection=pg_connect("","","template1");
 echo "$connection \"".getenv("PGDATESTYLE"),"\" \"".getenv("PGUSER"),"\"\n";
 if(($connection)>0)
  return($connection);
 $error=(IsSet($php_errormsg) ? $php_errormsg : "Could not connect to PostgreSQL server");
 return(0);
}

 $error="";
 if(($connection=Connect(&$error)))
 {
  pg_Close($connection);
  if($connection=Connect(&$error))
   pg_Close($connection);
 }
 if(strcmp($error,""))
  echo "Error: $error\n";
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-05-21 18:17 UTC] jah at cvs dot php dot net
This is not actually PostgreSQL related in any way, it happens because
putenv() accidentally modifies its input argument, and (probably) because
the Zend engine is so clever that there's only one copy of the string given
as argument to putenv(). After the first call, = in it will change to NULL.

Fix will be in cvs in few minutes, unless it immediately breaks up somethingg
else. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 12:01:31 2024 UTC