3 include_once("MDB2.php");
11 var $database = false;
13 function mydb($host,$db,$user,$pass,$port,$proto,$error,$debug) {
14 $this->error = $error;
15 $dsn = array('phptype' => $proto,
21 $this->debug = $debug;
22 $this->database = "-< $db >-";
26 function connect($dsn) {
27 $options = array('result_buffering' => false,);
28 $this->db = MDB2::connect($dsn,$options);
29 if ( $this->debug ) $this->error->write('dblib->connect '.$this->database,'Connect:');
30 if (PEAR::isError($this->db)) {
31 $this->error->write('dblib->connect '.$this->database,$this->db->getMessage());
32 $this->error->write('dblib->connect '.$this->database,print_r($dsn,true));
36 $this->db->setFetchMode(MDB2_FETCHMODE_ASSOC);
39 return $this->db->beginTransaction();
42 return $this->db->commit();
45 return $this->db->rollback();
48 function getAll($sql) {
49 $rs = $this->db->queryAll($sql);
50 if ( $this->debug ) $this->error->write('dblib->getAll '.$this->database,$sql);
51 if (PEAR::isError($rs)) {
52 $this->error->write('dblib->getAll '.$this->database,$rs->getUserinfo());
58 function getOne($sql) {
59 $rs = $this->db->queryRow($sql);
60 if ( $this->debug ) $this->error->write('dblib->getOne '.$this->database,$sql);
61 if (PEAR::isError($rs)) {
62 $this->error->write('dblib->getOne '.$this->database,$rs->getUserinfo());
67 function query($sql) {
68 $rc = $this->db->query($sql);
69 if ( $this->debug ) $this->error->write('dblib->query '.$this->database,$sql);
70 if (PEAR::isError($rc)) {
71 $this->error->write('dblib->query '.$this->database,$rc->getUserinfo());
76 function insert($statement,$data) {
77 if ( $this->debug ) $this->error->write("dblib->insert ".$this->database,$statement);
78 $sth = $this->db->prepare($statement); //Prepare
79 if (PEAR::isError($sth)) {
80 $this->error->write('dblib->insert 1 '.$this->database,$sth->getMessage());
81 $this->error->write('dblib->insert 2',$sth->getUserinfo());
85 if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
86 $rc =& $sth->execute($data);
87 if (PEAR::isError($rc)) {
88 $this->error->write('dblib->insert 3 '.$this->database,$rc->getUserinfo());
91 // $rc = $this->commit();
95 function update($statement,$data) {
96 if ( $this->debug ) $this->error->write("dblib->update ".$this->database,$statement);
97 $sth = $this->db->prepare($statement); //Prepare
98 if (PEAR::isError($sth)) {
99 $this->error->write('dblib->update 1 '.$this->database,$sth->getMessage());
100 $this->error->write('dblib->update 2',$sth->getUserinfo());
104 if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
105 $rc =& $sth->execute($data);
106 if (PEAR::isError($rc)) {
107 $this->error->write('dblib->update 3 '.$this->database,$rc->getUserinfo());
110 // $rc = $this->commit();
114 function insertMultipe($statement,$data) {
115 $this->db->loadModule('Extended');
116 if (!$this->db->supports('transactions')){
119 $sth = $this->db->prepare($statement); //Prepare
120 if (PEAR::isError($sth)) {
121 $this->error->write('dblib->insertMultiple '.$this->database,$sth->getMessage());
125 $rc =& $this->db->beginTransaction();
126 $rc =& $this->db->extended->executeMultiple($sth, $data);
127 if (PEAR::isError($rc)) {
128 $this->error->write('dblib->insertMultiple '.$this->database,$rc->getUserinfo());
132 $rc = $this->commit();