Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 7e28f16e

Von Holger Lindemann vor mehr als 12 Jahren hinzugefügt

  • ID 7e28f16efbb81644815ef06396b1d5c89c8bb5ec
  • Vorgänger b81f2b8f
  • Nachfolger 2d16e7a2

Diverse Verbesserungen u.a. Debugging

Unterschiede anzeigen:

peppershop/dblib.php
8 8
   var $error = false;
9 9
   var $debug = true;
10 10
   var $dbf = false;
11
   var $database = false;
11 12

  
12
   function mydb($host,$db,$user,$pass,$port,$proto,$error) {
13
   function mydb($host,$db,$user,$pass,$port,$proto,$error,$debug) {
13 14
       $this->error = $error;
14 15
       $dsn = array('phptype'  => $proto,
15 16
               'username' => $user,
......
17 18
               'hostspec' => $host,
18 19
               'database' => $db,
19 20
               'port'     => $port);
20
       if ( $this->debug ) {
21
            $this->dbf = fopen ("tmp/shop.log","w");
22
            if ( !$this->dbf ) $this->debug = false;
23
       }
21
       $this->debug = $debug;
22
       $this->database = "-< $db >-";
24 23
       $this->connect($dsn);
25 24
    }
26 25

  
27
    function log($txt) {
28
       $now = date('Y-m-d H:i:s');
29
       fputs($this->dbf,$now." : ".$txt."\n");
30
    }
31 26
    function connect($dsn) {
32 27
       $options = array('result_buffering' => false,);
33 28
       $this->db = MDB2::connect($dsn,$options);
34
       if ( $this->debug ) $this->log('Connect:');
29
       if ( $this->debug ) $this->error->write('dblib->connect '.$this->database,'Connect:');
35 30
       if (PEAR::isError($this->db)) {
36
           if ( $this->debug ) $this->log($this->db->getMessage());
37
           $this->error->write('dblib->connect',$this->db->getMessage());
38
           $this->error->write('dblib->connect',print_r($dsn,true));
31
           $this->error->write('dblib->connect '.$this->database,$this->db->getMessage());
32
           $this->error->write('dblib->connect '.$this->database,print_r($dsn,true));
39 33
           $this->db = false;
40 34
           return false;
41 35
       }
......
53 47

  
54 48
    function getAll($sql) {
55 49
        $rs = $this->db->queryAll($sql);
56
        if ( $this->debug ) $this->log($sql);
50
        if ( $this->debug ) $this->error->write('dblib->getAll '.$this->database,$sql);
57 51
        if (PEAR::isError($rs)) {
58
            if ( $this->debug ) $this->log($rs->getUserinfo());
59
            $this->error->write('dblib->getAll',$rs->getUserinfo());
52
            $this->error->write('dblib->getAll '.$this->database,$rs->getUserinfo());
60 53
            return false;
61 54
        }
62 55
        return $rs;
......
64 57
 
65 58
    function getOne($sql) {
66 59
        $rs = $this->db->queryRow($sql);
67
        if ( $this->debug ) $this->log($sql);
60
        if ( $this->debug ) $this->error->write('dblib->getOne '.$this->database,$sql);
68 61
        if (PEAR::isError($rs)) {
69
            if ( $this->debug ) $this->log($rs->getUserinfo());
70
            $this->error->write('dblib->getOne',$rs->getUserinfo());
62
            $this->error->write('dblib->getOne '.$this->database,$rs->getUserinfo());
71 63
            return false;
72 64
        }
73 65
        return $rs;
74 66
    }
75 67
    function query($sql) {
76 68
        $rc = $this->db->query($sql);
77
        if ( $this->debug ) $this->log($sql);
69
        if ( $this->debug ) $this->error->write('dblib->query '.$this->database,$sql);
78 70
        if (PEAR::isError($rc)) {
79
            if ( $this->debug ) $this->log($rc->getUserinfo());
80
            $this->error->write('dblib->query',$rc->getUserinfo());
71
            $this->error->write('dblib->query '.$this->database,$rc->getUserinfo());
81 72
            return false;
82 73
        }
83 74
        return $rc;
84 75
    } 
85 76
    function insert($statement,$data) {
86
        if ( $this->debug ) $this->log("INSERT ".$statement);
77
        if ( $this->debug ) $this->error->write("dblib->insert ".$this->database,$statement);
87 78
        $sth = $this->db->prepare($statement);                      //Prepare
88 79
        if (PEAR::isError($sth)) {
89
            $this->error->write('dblib->insert 1',$sth->getMessage());
80
            $this->error->write('dblib->insert 1 '.$this->database,$sth->getMessage());
90 81
            $this->error->write('dblib->insert 2',$sth->getUserinfo());
91 82
            $this->rollback();
92 83
            return false;
93 84
        }
94
        if ( $this->debug ) $this->log(print_r($data,true));
85
        if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
95 86
        $rc =& $sth->execute($data);
96 87
        if (PEAR::isError($rc)) {
97
            if ( $this->debug ) $this->log($rc->getUserinfo());
98
            $this->error->write('dblib->insert 3',$rc->getUserinfo());
88
            $this->error->write('dblib->insert 3 '.$this->database,$rc->getUserinfo());
99 89
            return false;
100 90
        }//else{
101 91
        //    $rc = $this->commit();
......
103 93
        return $rc;
104 94
    }
105 95
    function update($statement,$data) {  
106
        if ( $this->debug ) $this->log("UPDATE ".$statement);
96
        if ( $this->debug ) $this->error->write("dblib->update ".$this->database,$statement);
107 97
        $sth = $this->db->prepare($statement);                      //Prepare
108 98
        if (PEAR::isError($sth)) {
109
            if ( $this->debug ) $this->log("ERRPOR ".$rc->getUserinfo());
110
            $this->error->write('dblib->update 1',$sth->getMessage());
99
            $this->error->write('dblib->update 1 '.$this->database,$sth->getMessage());
111 100
            $this->error->write('dblib->update 2',$sth->getUserinfo());
112 101
            $this->rollback();
113 102
            return false;
114 103
        }
115
        if ( $this->debug ) $this->log(print_r($data,true));
104
        if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
116 105
        $rc =& $sth->execute($data);
117 106
        if (PEAR::isError($rc)) {
118
            if ( $this->debug ) $this->log("ERRPOR ".$rc->getUserinfo());
119
            $this->error->write('dblib->update 3',$rc->getUserinfo());
107
            $this->error->write('dblib->update 3 '.$this->database,$rc->getUserinfo());
120 108
            return false;
121 109
        }//else{
122 110
        //    $rc = $this->commit();
......
130 118
        }
131 119
        $sth = $this->db->prepare($statement);                      //Prepare
132 120
        if (PEAR::isError($sth)) {
133
            $this->error->write('dblib->insertMultiple',$sth->getMessage());
121
            $this->error->write('dblib->insertMultiple '.$this->database,$sth->getMessage());
134 122
            $this->rollback();
135 123
            return false;
136 124
        }
137 125
        $rc =& $this->db->beginTransaction();
138 126
        $rc =& $this->db->extended->executeMultiple($sth, $data);
139 127
        if (PEAR::isError($rc)) {
140
            $this->error->write('dblib->insertMultiple',$rc->getUserinfo());
128
            $this->error->write('dblib->insertMultiple '.$this->database,$rc->getUserinfo());
141 129
            $this->rollback();
142 130
            return false;
143 131
        }else{

Auch abrufbar als: Unified diff