[phplib] Closing postgres connections From: Frederic De Leersnijder (Frederic.De.Leersnijder <email protected>)
Date: 07/18/00

I tried to dump my database and it was in use by other users. No problem,
I'll close all the database proggies. But that didn't help and then I looked
what kind of processes there were running. It seemed that all my persistent
connections were still alive. (Read: I forgot to close them with pg_Close())
Now I close my connection at the end of the script but the first child stays
alive.
So, I open a connection, the postmaster forks (or something) & when I close
it at the end of the script the connection remains open. When I rerun the
script the connection is closed the right way.
I don't know how to close it because it looks quite simple. I open a
connection and I close it at the end. This works except the first time.

greets
frederic

This is my script

<? page_open(array("sess" => "Library_Session_Admin"));

require("class.layout");
error_reporting(0);

// Make up the window
setdefault("window",array("bgcolor"=>"white"));
setdefault("text",array("size"=>"2"));
newhtml(&$w);
insert($w,wheader( "Importeren gemeentes"));

// Open a new database connection
$db = new DB_Library_Admin;
$db->Halt_On_Error="no";
$db->begin();

// Put each line of the file in the array & process
$cities = file("cities.txt");

for (reset($cities);current($cities);next($cities)) {

 // Seperate cityname & cityzip
 // Prepare the cityname
 // Prepare the cityzip (Remove spaces so it can be seen as an integer)

 $cityinfo = ereg_replace("[[:space:]]+", " ", $cityinfo);
 $cityinfo = explode("|", current($cities));
 $cityname = $cityinfo[0];
 $cityzip = trim($cityinfo[1]);

 $tempname = explode("-", $cityname);
 unset($cityname);
 for (reset($tempname);current($tempname);next($tempname)) {
   $temp = current($tempname);
   $temp = ucwords(strtolower($temp));
  $cityname = $cityname . "-" . $temp;
 }

 // Remove the trailing -

 $cityname = ereg_replace("^[-]", "", $cityname);
 $cityname = addslashes($cityname);
 $text = "Gemeentenaam: " . stripslashes($cityname) . " Postcode: " .
$cityzip;

  // Insert the data in the cities table

 $query = "INSERT INTO cities (cityname, cityzip) values ('$cityname',
$cityzip)";
 $db->Query($query);
 if ($db->Errno) {
  break;
 } else {
 insert($w, text($text));
 $text = " Toegevoegd" . "<br>";
 insert($w, text($text));
 }

}
if ($db->Errno) {
 $db->rollback();
} else {
 $db->commit();
 printhtml($w);
}
pg_Close($db->Link_ID);
page_close();
?>

---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>