3 class myDB extends DB {
7 var $showErr = false; // Browserausgabe
8 var $debug = false; // 1 = SQL-Ausgabe, 2 = zusätzlich Ergebnis
9 var $log = true; // Alle Abfragen mitloggen
10 var $errfile = "tmp/lxcrm.err";
11 var $logfile = "tmp/lxcrm.log";
14 function dbFehler($sql,$err) {
15 $efh=fopen($this->errfile,"a");
16 fputs($efh,date("Y-m-d H:i:s ->"));
17 fputs($efh,$sql."\n");
18 fputs($efh,$err."\n");
19 fputs($efh,print_r($this->rc,true));
23 echo "</td></tr></table><font color='red'>$sql : $err</font><br>";
26 function showDebug($sql) {
28 if ($this->debug==2) {
35 function writeLog($txt) {
36 if ($this->lfh===false)
37 $this->lfh=fopen($this->logfile,"a");
38 fputs($this->lfh,date("Y-m-d H:i:s ->"));
39 fputs($this->lfh,$txt."\n");
40 fputs($this->lfh,print_r($this->rc,true));
41 fputs($this->lfh,"\n");
44 function closeLogfile() {
48 function myDB($host,$user,$pwd,$db,$port,$showErr=false) {
57 $this->showErr=$showErr;
58 $this->db=DB::connect($dsn);
59 if (!$this->db || DB::isError($this->db)) {
60 if ($this->log) $this->writeLog("Connect $dns");
61 $this->dbFehler("Connect ".print_r($dsn,true),$this->db->getMessage());
62 die ($this->db->getMessage());
64 if ($this->log) $this->writeLog("Connect: ok ");
68 function query($sql) {
69 $this->rc=@$this->db->query($sql);
70 if ($this->debug) $this->showDebug($sql);
71 if ($this->log) $this->writeLog($sql);
72 if(DB::isError($this->rc)) {
73 $this->dbFehler($sql,$this->rc->getMessage());
82 $this->query("BEGIN");
85 $this->query("COMMIT");
88 $this->query("ROLLBACK");
91 function getAll($sql) {
92 $this->rc=$this->db->getAll($sql,DB_FETCHMODE_ASSOC);
93 if ($this->debug) $this->showDebug($sql);
94 if ($this->log) $this->writeLog($sql);
95 if(DB::isError($this->rc)) {
96 $this->dbFehler($sql,$this->rc->getMessage());
103 function saveData($txt) {
104 if (get_magic_quotes_gpc()) {
107 return DB::quoteSmart($string);
111 function chkcol($tbl) {
112 // gibt es die Spalte import schon?
113 $rc=$this->db->query("select import from $tbl limit 1");
114 if(DB::isError($rc)) {
115 $rc=$this->db->query("alter table $tbl add column import int4");
116 if(DB::isError($rc)) { return false; }
117 else { return true; }
118 } else { return true; };