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
13 function dbFehler($sql,$err) {
14 $efh=fopen($this->path."lxcrm".date("w").".err","a");
15 fputs($efh,date("Y-m-d H:i:s ->"));
16 fputs($efh,$sql."\n");
17 fputs($efh,$err."\n");
18 fputs($efh,print_r($this->rc,true));
22 echo "</td></tr></table><font color='red'>$sql : $err</font><br>";
25 function showDebug($sql) {
27 if ($this->debug==2) {
34 function writeLog($txt) {
35 if ($this->lfh===false)
36 $this->lfh=fopen($this->path."lxcrm".date("w").".log","a");
37 fputs($this->lfh,date("Y-m-d H:i:s ->"));
38 fputs($this->lfh,$txt."\n");
39 fputs($this->lfh,print_r($this->rc,true));
40 fputs($this->lfh,"\n");
43 function closeLogfile() {
47 function myDB($host,$user,$pwd,$db,$port,$showErr=false) {
56 $this->showErr=$showErr;
57 $this->db=DB::connect($dsn);
58 if (!$this->db || DB::isError($this->db)) {
59 if ($this->log) $this->writeLog("Connect $dns");
60 $this->dbFehler("Connect ".print_r($dsn,true),$this->db->getMessage());
61 die ($this->db->getMessage());
63 if ($this->log) $this->writeLog("Connect: ok ");
67 function query($sql) {
68 $this->rc=@$this->db->query($sql);
69 if ($this->debug) $this->showDebug($sql);
70 if ($this->log) $this->writeLog($sql);
71 if(DB::isError($this->rc)) {
72 $this->dbFehler($sql,$this->rc->getMessage());
81 $this->query("BEGIN");
84 $this->query("COMMIT");
87 $this->query("ROLLBACK");
90 function getAll($sql) {
91 $this->rc=$this->db->getAll($sql,DB_FETCHMODE_ASSOC);
92 if ($this->debug) $this->showDebug($sql);
93 if ($this->log) $this->writeLog($sql);
94 if(DB::isError($this->rc)) {
95 $this->dbFehler($sql,$this->rc->getMessage());
102 function saveData($txt) {
103 if (get_magic_quotes_gpc()) {
106 return DB::quoteSmart($string);
110 function execute($statement, $data){
111 $sth = $this->db->prepare($statement); //Prepare
112 /*if (PEAR::isError($sth)) {
113 $this->dbFehler($statement,$sth->getMessage());
117 $rc = $this->db->execute($sth,$data);
118 if(PEAR::isError($rc)) {
119 $this->dbFehler(print_r($data,true),$rc->getMessage()."\n".print_r($rc,true));
127 function chkcol($tbl) {
128 // gibt es die Spalte import schon?
129 $rc=$this->db->query("select import from $tbl limit 1");
130 if(DB::isError($rc)) {
131 $rc=$this->db->query("alter table $tbl add column import int4");
132 if(DB::isError($rc)) { return false; }
133 else { return true; }
134 } else { return true; };
138 * Zeichekodirung der DB ermitteln
142 function getServerCode() {
143 $sql="SHOW server_encoding";
144 $rs = $this->getAll($sql);
145 return $rs[0]["server_encoding"];
147 function getClientCode() {
148 $sql="SHOW client_encoding";
149 $rs = $this->getAll($sql);
150 return $rs[0]["client_encoding"];
152 function setClientCode($encoding) {
153 $sql="SET client_encoding = '$encoding'";
154 $rc = $this->query($sql);