kivitendo/peppershop/dblib.php @ b3298009
0873c774 | Holger Lindemann | <?php
|
||
include_once("MDB2.php");
|
||||
class mydb {
|
||||
var $db = false;
|
||||
var $error = false;
|
||||
var $debug = true;
|
||||
var $dbf = false;
|
||||
7e28f16e | Holger Lindemann | var $database = false;
|
||
0873c774 | Holger Lindemann | |||
7e28f16e | Holger Lindemann | function mydb($host,$db,$user,$pass,$port,$proto,$error,$debug) {
|
||
0873c774 | Holger Lindemann | $this->error = $error;
|
||
$dsn = array('phptype' => $proto,
|
||||
'username' => $user,
|
||||
'password' => $pass,
|
||||
'hostspec' => $host,
|
||||
'database' => $db,
|
||||
'port' => $port);
|
||||
7e28f16e | Holger Lindemann | $this->debug = $debug;
|
||
$this->database = "-< $db >-";
|
||||
0873c774 | Holger Lindemann | $this->connect($dsn);
|
||
}
|
||||
function connect($dsn) {
|
||||
$options = array('result_buffering' => false,);
|
||||
$this->db = MDB2::connect($dsn,$options);
|
||||
7e28f16e | Holger Lindemann | if ( $this->debug ) $this->error->write('dblib->connect '.$this->database,'Connect:');
|
||
0873c774 | Holger Lindemann | if (PEAR::isError($this->db)) {
|
||
7e28f16e | Holger Lindemann | $this->error->write('dblib->connect '.$this->database,$this->db->getMessage());
|
||
$this->error->write('dblib->connect '.$this->database,print_r($dsn,true));
|
||||
0873c774 | Holger Lindemann | $this->db = false;
|
||
return false;
|
||||
}
|
||||
$this->db->setFetchMode(MDB2_FETCHMODE_ASSOC);
|
||||
}
|
||||
function Begin() {
|
||||
return $this->db->beginTransaction();
|
||||
}
|
||||
function Commit() {
|
||||
return $this->db->commit();
|
||||
}
|
||||
function Rollback() {
|
||||
return $this->db->rollback();
|
||||
}
|
||||
function getAll($sql) {
|
||||
$rs = $this->db->queryAll($sql);
|
||||
7e28f16e | Holger Lindemann | if ( $this->debug ) $this->error->write('dblib->getAll '.$this->database,$sql);
|
||
0873c774 | Holger Lindemann | if (PEAR::isError($rs)) {
|
||
7e28f16e | Holger Lindemann | $this->error->write('dblib->getAll '.$this->database,$rs->getUserinfo());
|
||
0873c774 | Holger Lindemann | return false;
|
||
}
|
||||
return $rs;
|
||||
}
|
||||
function getOne($sql) {
|
||||
$rs = $this->db->queryRow($sql);
|
||||
7e28f16e | Holger Lindemann | if ( $this->debug ) $this->error->write('dblib->getOne '.$this->database,$sql);
|
||
0873c774 | Holger Lindemann | if (PEAR::isError($rs)) {
|
||
7e28f16e | Holger Lindemann | $this->error->write('dblib->getOne '.$this->database,$rs->getUserinfo());
|
||
0873c774 | Holger Lindemann | return false;
|
||
}
|
||||
return $rs;
|
||||
}
|
||||
function query($sql) {
|
||||
$rc = $this->db->query($sql);
|
||||
7e28f16e | Holger Lindemann | if ( $this->debug ) $this->error->write('dblib->query '.$this->database,$sql);
|
||
0873c774 | Holger Lindemann | if (PEAR::isError($rc)) {
|
||
7e28f16e | Holger Lindemann | $this->error->write('dblib->query '.$this->database,$rc->getUserinfo());
|
||
0873c774 | Holger Lindemann | return false;
|
||
}
|
||||
return $rc;
|
||||
}
|
||||
function insert($statement,$data) {
|
||||
7e28f16e | Holger Lindemann | if ( $this->debug ) $this->error->write("dblib->insert ".$this->database,$statement);
|
||
0873c774 | Holger Lindemann | $sth = $this->db->prepare($statement); //Prepare
|
||
if (PEAR::isError($sth)) {
|
||||
7e28f16e | Holger Lindemann | $this->error->write('dblib->insert 1 '.$this->database,$sth->getMessage());
|
||
0873c774 | Holger Lindemann | $this->error->write('dblib->insert 2',$sth->getUserinfo());
|
||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
7e28f16e | Holger Lindemann | if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
|
||
0873c774 | Holger Lindemann | $rc =& $sth->execute($data);
|
||
if (PEAR::isError($rc)) {
|
||||
7e28f16e | Holger Lindemann | $this->error->write('dblib->insert 3 '.$this->database,$rc->getUserinfo());
|
||
0873c774 | Holger Lindemann | return false;
|
||
}//else{
|
||||
// $rc = $this->commit();
|
||||
//}
|
||||
return $rc;
|
||||
}
|
||||
function update($statement,$data) {
|
||||
7e28f16e | Holger Lindemann | if ( $this->debug ) $this->error->write("dblib->update ".$this->database,$statement);
|
||
0873c774 | Holger Lindemann | $sth = $this->db->prepare($statement); //Prepare
|
||
if (PEAR::isError($sth)) {
|
||||
7e28f16e | Holger Lindemann | $this->error->write('dblib->update 1 '.$this->database,$sth->getMessage());
|
||
0873c774 | Holger Lindemann | $this->error->write('dblib->update 2',$sth->getUserinfo());
|
||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
7e28f16e | Holger Lindemann | if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
|
||
0873c774 | Holger Lindemann | $rc =& $sth->execute($data);
|
||
if (PEAR::isError($rc)) {
|
||||
7e28f16e | Holger Lindemann | $this->error->write('dblib->update 3 '.$this->database,$rc->getUserinfo());
|
||
0873c774 | Holger Lindemann | return false;
|
||
}//else{
|
||||
// $rc = $this->commit();
|
||||
//}
|
||||
return $rc;
|
||||
}
|
||||
function insertMultipe($statement,$data) {
|
||||
$this->db->loadModule('Extended');
|
||||
if (!$this->db->supports('transactions')){
|
||||
return false;
|
||||
}
|
||||
$sth = $this->db->prepare($statement); //Prepare
|
||||
if (PEAR::isError($sth)) {
|
||||
7e28f16e | Holger Lindemann | $this->error->write('dblib->insertMultiple '.$this->database,$sth->getMessage());
|
||
0873c774 | Holger Lindemann | $this->rollback();
|
||
return false;
|
||||
}
|
||||
$rc =& $this->db->beginTransaction();
|
||||
$rc =& $this->db->extended->executeMultiple($sth, $data);
|
||||
if (PEAR::isError($rc)) {
|
||||
7e28f16e | Holger Lindemann | $this->error->write('dblib->insertMultiple '.$this->database,$rc->getUserinfo());
|
||
0873c774 | Holger Lindemann | $this->rollback();
|
||
return false;
|
||||
}else{
|
||||
$rc = $this->commit();
|
||||
}
|
||||
return $rc;
|
||||
}
|
||||
}
|
||||
?>
|