DeliveryPlan
[kivitendo-erp.git] / peppershop / dblib.php
index 6420749..c0797b6 100644 (file)
@@ -8,8 +8,9 @@ class mydb {
    var $error = false;
    var $debug = true;
    var $dbf = false;
+   var $database = false;
 
-   function mydb($host,$db,$user,$pass,$port,$proto,$error) {
+   function mydb($host,$db,$user,$pass,$port,$proto,$error,$debug) {
        $this->error = $error;
        $dsn = array('phptype'  => $proto,
                'username' => $user,
@@ -17,25 +18,18 @@ class mydb {
                'hostspec' => $host,
                'database' => $db,
                'port'     => $port);
-       if ( $this->debug ) {
-            $this->dbf = fopen ("tmp/shop.log","w");
-            if ( !$this->dbf ) $this->debug = false;
-       }
+       $this->debug = $debug;
+       $this->database = "-< $db >-";
        $this->connect($dsn);
     }
 
-    function log($txt) {
-       $now = date('Y-m-d H:i:s');
-       fputs($this->dbf,$now." : ".$txt."\n");
-    }
     function connect($dsn) {
        $options = array('result_buffering' => false,);
        $this->db = MDB2::connect($dsn,$options);
-       if ( $this->debug ) $this->log('Connect:');
+       if ( $this->debug ) $this->error->write('dblib->connect '.$this->database,'Connect:');
        if (PEAR::isError($this->db)) {
-           if ( $this->debug ) $this->log($this->db->getMessage());
-           $this->error->write('dblib->connect',$this->db->getMessage());
-           $this->error->write('dblib->connect',print_r($dsn,true));
+           $this->error->write('dblib->connect '.$this->database,$this->db->getMessage());
+           $this->error->write('dblib->connect '.$this->database,print_r($dsn,true));
            $this->db = false;
            return false;
        }
@@ -53,10 +47,9 @@ class mydb {
 
     function getAll($sql) {
         $rs = $this->db->queryAll($sql);
-        if ( $this->debug ) $this->log($sql);
+        if ( $this->debug ) $this->error->write('dblib->getAll '.$this->database,$sql);
         if (PEAR::isError($rs)) {
-            if ( $this->debug ) $this->log($rs->getUserinfo());
-            $this->error->write('dblib->getAll',$rs->getUserinfo());
+            $this->error->write('dblib->getAll '.$this->database,$rs->getUserinfo());
             return false;
         }
         return $rs;
@@ -64,38 +57,35 @@ class mydb {
  
     function getOne($sql) {
         $rs = $this->db->queryRow($sql);
-        if ( $this->debug ) $this->log($sql);
+        if ( $this->debug ) $this->error->write('dblib->getOne '.$this->database,$sql);
         if (PEAR::isError($rs)) {
-            if ( $this->debug ) $this->log($rs->getUserinfo());
-            $this->error->write('dblib->getOne',$rs->getUserinfo());
+            $this->error->write('dblib->getOne '.$this->database,$rs->getUserinfo());
             return false;
         }
         return $rs;
     }
     function query($sql) {
         $rc = $this->db->query($sql);
-        if ( $this->debug ) $this->log($sql);
+        if ( $this->debug ) $this->error->write('dblib->query '.$this->database,$sql);
         if (PEAR::isError($rc)) {
-            if ( $this->debug ) $this->log($rc->getUserinfo());
-            $this->error->write('dblib->query',$rc->getUserinfo());
+            $this->error->write('dblib->query '.$this->database,$rc->getUserinfo());
             return false;
         }
         return $rc;
     } 
     function insert($statement,$data) {
-        if ( $this->debug ) $this->log("INSERT ".$statement);
+        if ( $this->debug ) $this->error->write("dblib->insert ".$this->database,$statement);
         $sth = $this->db->prepare($statement);                      //Prepare
         if (PEAR::isError($sth)) {
-            $this->error->write('dblib->insert 1',$sth->getMessage());
+            $this->error->write('dblib->insert 1 '.$this->database,$sth->getMessage());
             $this->error->write('dblib->insert 2',$sth->getUserinfo());
             $this->rollback();
             return false;
         }
-        if ( $this->debug ) $this->log(print_r($data,true));
+        if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
         $rc =& $sth->execute($data);
         if (PEAR::isError($rc)) {
-            if ( $this->debug ) $this->log($rc->getUserinfo());
-            $this->error->write('dblib->insert 3',$rc->getUserinfo());
+            $this->error->write('dblib->insert 3 '.$this->database,$rc->getUserinfo());
             return false;
         }//else{
         //    $rc = $this->commit();
@@ -103,20 +93,18 @@ class mydb {
         return $rc;
     }
     function update($statement,$data) {  
-        if ( $this->debug ) $this->log("UPDATE ".$statement);
+        if ( $this->debug ) $this->error->write("dblib->update ".$this->database,$statement);
         $sth = $this->db->prepare($statement);                      //Prepare
         if (PEAR::isError($sth)) {
-            if ( $this->debug ) $this->log("ERRPOR ".$rc->getUserinfo());
-            $this->error->write('dblib->update 1',$sth->getMessage());
+            $this->error->write('dblib->update 1 '.$this->database,$sth->getMessage());
             $this->error->write('dblib->update 2',$sth->getUserinfo());
             $this->rollback();
             return false;
         }
-        if ( $this->debug ) $this->log(print_r($data,true));
+        if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
         $rc =& $sth->execute($data);
         if (PEAR::isError($rc)) {
-            if ( $this->debug ) $this->log("ERRPOR ".$rc->getUserinfo());
-            $this->error->write('dblib->update 3',$rc->getUserinfo());
+            $this->error->write('dblib->update 3 '.$this->database,$rc->getUserinfo());
             return false;
         }//else{
         //    $rc = $this->commit();
@@ -130,14 +118,14 @@ class mydb {
         }
         $sth = $this->db->prepare($statement);                      //Prepare
         if (PEAR::isError($sth)) {
-            $this->error->write('dblib->insertMultiple',$sth->getMessage());
+            $this->error->write('dblib->insertMultiple '.$this->database,$sth->getMessage());
             $this->rollback();
             return false;
         }
         $rc =& $this->db->beginTransaction();
         $rc =& $this->db->extended->executeMultiple($sth, $data);
         if (PEAR::isError($rc)) {
-            $this->error->write('dblib->insertMultiple',$rc->getUserinfo());
+            $this->error->write('dblib->insertMultiple '.$this->database,$rc->getUserinfo());
             $this->rollback();
             return false;
         }else{