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());
 
  89             $this->error->write('SQL ',$statement);
 
  90             $this->error->write('Data ',print_r($data,true));
 
  93         //    $rc = $this->commit();
 
  97     function update($statement,$data) {  
 
  98         if ( $this->debug ) $this->error->write("dblib->update ".$this->database,$statement);
 
  99         $sth = $this->db->prepare($statement);                      //Prepare
 
 100         if (PEAR::isError($sth)) {
 
 101             $this->error->write('dblib->update 1 '.$this->database,$sth->getMessage());
 
 102             $this->error->write('dblib->update 2',$sth->getUserinfo());
 
 106         if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
 
 107         $rc =& $sth->execute($data);
 
 108         if (PEAR::isError($rc)) {
 
 109             $this->error->write('dblib->update 3 '.$this->database,$rc->getUserinfo());
 
 112         //    $rc = $this->commit();
 
 116     function insertMultipe($statement,$data) {
 
 117         $this->db->loadModule('Extended');
 
 118         if (!$this->db->supports('transactions')){
 
 121         $sth = $this->db->prepare($statement);                      //Prepare
 
 122         if (PEAR::isError($sth)) {
 
 123             $this->error->write('dblib->insertMultiple '.$this->database,$sth->getMessage());
 
 127         $rc =& $this->db->beginTransaction();
 
 128         $rc =& $this->db->extended->executeMultiple($sth, $data);
 
 129         if (PEAR::isError($rc)) {
 
 130             $this->error->write('dblib->insertMultiple '.$this->database,$rc->getUserinfo());
 
 134                 $rc = $this->commit();