3 include_once("MDB2.php");
12 function mydb($host,$db,$user,$pass,$port,$proto,$error) {
13 $this->error = $error;
14 $dsn = array('phptype' => $proto,
21 $this->dbf = fopen ("tmp/shop.log","w");
22 if ( !$this->dbf ) $this->debug = false;
28 $now = date('Y-m-d H:i:s');
29 fputs($this->dbf,$now." : ".$txt."\n");
31 function connect($dsn) {
32 $options = array('result_buffering' => false,);
33 $this->db = MDB2::connect($dsn,$options);
34 if ( $this->debug ) $this->log('Connect:');
35 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));
42 $this->db->setFetchMode(MDB2_FETCHMODE_ASSOC);
45 return $this->db->beginTransaction();
48 return $this->db->commit();
51 return $this->db->rollback();
54 function getAll($sql) {
55 $rs = $this->db->queryAll($sql);
56 if ( $this->debug ) $this->log($sql);
57 if (PEAR::isError($rs)) {
58 if ( $this->debug ) $this->log($rs->getUserinfo());
59 $this->error->write('dblib->getAll',$rs->getUserinfo());
65 function getOne($sql) {
66 $rs = $this->db->queryRow($sql);
67 if ( $this->debug ) $this->log($sql);
68 if (PEAR::isError($rs)) {
69 if ( $this->debug ) $this->log($rs->getUserinfo());
70 $this->error->write('dblib->getOne',$rs->getUserinfo());
75 function query($sql) {
76 $rc = $this->db->query($sql);
77 if ( $this->debug ) $this->log($sql);
78 if (PEAR::isError($rc)) {
79 if ( $this->debug ) $this->log($rc->getUserinfo());
80 $this->error->write('dblib->query',$rc->getUserinfo());
85 function insert($statement,$data) {
86 if ( $this->debug ) $this->log("INSERT ".$statement);
87 $sth = $this->db->prepare($statement); //Prepare
88 if (PEAR::isError($sth)) {
89 $this->error->write('dblib->insert 1',$sth->getMessage());
90 $this->error->write('dblib->insert 2',$sth->getUserinfo());
94 if ( $this->debug ) $this->log(print_r($data,true));
95 $rc =& $sth->execute($data);
96 if (PEAR::isError($rc)) {
97 if ( $this->debug ) $this->log($rc->getUserinfo());
98 $this->error->write('dblib->insert 3',$rc->getUserinfo());
101 // $rc = $this->commit();
105 function update($statement,$data) {
106 if ( $this->debug ) $this->log("UPDATE ".$statement);
107 $sth = $this->db->prepare($statement); //Prepare
108 if (PEAR::isError($sth)) {
109 if ( $this->debug ) $this->log("ERRPOR ".$rc->getUserinfo());
110 $this->error->write('dblib->update 1',$sth->getMessage());
111 $this->error->write('dblib->update 2',$sth->getUserinfo());
115 if ( $this->debug ) $this->log(print_r($data,true));
116 $rc =& $sth->execute($data);
117 if (PEAR::isError($rc)) {
118 if ( $this->debug ) $this->log("ERRPOR ".$rc->getUserinfo());
119 $this->error->write('dblib->update 3',$rc->getUserinfo());
122 // $rc = $this->commit();
126 function insertMultipe($statement,$data) {
127 $this->db->loadModule('Extended');
128 if (!$this->db->supports('transactions')){
131 $sth = $this->db->prepare($statement); //Prepare
132 if (PEAR::isError($sth)) {
133 $this->error->write('dblib->insertMultiple',$sth->getMessage());
137 $rc =& $this->db->beginTransaction();
138 $rc =& $this->db->extended->executeMultiple($sth, $data);
139 if (PEAR::isError($rc)) {
140 $this->error->write('dblib->insertMultiple',$rc->getUserinfo());
144 $rc = $this->commit();