X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=lxo-import%2Fdb.php;h=a7b030d4ebc779bcdf8b2ecdf77cb10121263c00;hb=914d2b3fda11d4cf465c0ee33f07c03fa2e1f45f;hp=51fa12f1a4b59017fb866c8d1c9c11b9dfb92301;hpb=e2903b0d056db3b97b846ddde87a44b4f5a10954;p=kivitendo-erp.git diff --git a/lxo-import/db.php b/lxo-import/db.php index 51fa12f1a..a7b030d4e 100644 --- a/lxo-import/db.php +++ b/lxo-import/db.php @@ -1,4 +1,4 @@ -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 dbFehler($sql,$err) { + $efh=fopen($this->path."lxcrm".date("w").".err","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 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 writeLog($txt) { + if ($this->lfh===false) + $this->lfh=fopen($this->path."lxcrm".date("w").".log","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( + function closeLogfile() { + fclose($this->lfh); + } + + function myDB($host,$user,$pwd,$db,$port,$showErr=false) { + $dsn = array( 'phptype' => 'pgsql', 'username' => $user, 'password' => $pwd, @@ -54,70 +53,107 @@ class myDB extends DB { '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; - } + $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 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 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 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 saveData($txt) { + if (get_magic_quotes_gpc()) { + return $txt; + } else { + return DB::quoteSmart($string); + } + } - function chkcol($tbl) { + function execute($statement, $data){ + $sth = $this->db->prepare($statement); //Prepare + /*if (PEAR::isError($sth)) { + $this->dbFehler($statement,$sth->getMessage()); + $this->rollback(); + return false; + }*/ + $rc = $this->db->execute($sth,$data); + if(PEAR::isError($rc)) { + $this->dbFehler(print_r($data,true),$rc->getMessage()."\n".print_r($rc,true)); + $this->rollback(); + return false; + } + $this->db->commit(); + return true; + } + + 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; }; - } + $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; }; + } + /** + * Zeichekodirung der DB ermitteln + * + * @return String + */ + function getServerCode() { + $sql="SHOW server_encoding"; + $rs = $this->getAll($sql); + return $rs[0]["server_encoding"]; + } + function getClientCode() { + $sql="SHOW client_encoding"; + $rs = $this->getAll($sql); + return $rs[0]["client_encoding"]; + } + function setClientCode($encoding) { + $sql="SET client_encoding = '$encoding'"; + $rc = $this->query($sql); + return $rc; + } } ?>