errfile,"a"); fputs($efh,date("Y-m-d H:i:s ->")); fputs($efh,$sql."\n"); fputs($efh,$err."\n"); fputs($efh,print_r($this->rc,true)); fputs($efh,"\n"); fclose($efh); if ($this->showErr) echo "$sql : $err
"; } function showDebug($sql) { echo $sql."
"; if ($this->debug==2) { echo "
";
			print_r($this->rc);
			echo "
"; }; } function writeLog($txt) { if ($this->lfh===false) $this->lfh=fopen($this->logfile,"a"); fputs($this->lfh,date("Y-m-d H:i:s ->")); fputs($this->lfh,$txt."\n"); fputs($this->lfh,print_r($this->rc,true)); fputs($this->lfh,"\n"); } function closeLogfile() { fclose($this->lfh); } function myDB($host,$user,$pwd,$db,$port,$showErr=false) { $dsn = array( 'phptype' => 'pgsql', 'username' => $user, 'password' => $pwd, 'hostspec' => $host, 'database' => $db, 'port' => $port ); $this->showErr=$showErr; $this->db=DB::connect($dsn); if (!$this->db || DB::isError($this->db)) { if ($this->log) $this->writeLog("Connect $dns"); $this->dbFehler("Connect ".print_r($dsn,true),$this->db->getMessage()); die ($this->db->getMessage()); } if ($this->log) $this->writeLog("Connect: ok "); return $this->db; } function query($sql) { $this->rc=@$this->db->query($sql); if ($this->debug) $this->showDebug($sql); if ($this->log) $this->writeLog($sql); if(DB::isError($this->rc)) { $this->dbFehler($sql,$this->rc->getMessage()); $this->rollback(); return false; } else { return $this->rc; } } function begin() { $this->query("BEGIN"); } function commit() { $this->query("COMMIT"); } function rollback() { $this->query("ROLLBACK"); } function getAll($sql) { $this->rc=$this->db->getAll($sql,DB_FETCHMODE_ASSOC); if ($this->debug) $this->showDebug($sql); if ($this->log) $this->writeLog($sql); if(DB::isError($this->rc)) { $this->dbFehler($sql,$this->rc->getMessage()); return false; } else { return $this->rc; } } function saveData($txt) { if (get_magic_quotes_gpc()) { return $txt; } else { return DB::quoteSmart($string); } } function chkcol($tbl) { // gibt es die Spalte import schon? $rc=$this->db->query("select import from $tbl limit 1"); if(DB::isError($rc)) { $rc=$this->db->query("alter table $tbl add column import int4"); if(DB::isError($rc)) { return false; } else { return true; } } else { return true; }; } } ?>