-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdblib.php
executable file
·138 lines (130 loc) · 4.78 KB
/
dblib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
include_once("MDB2.php");
class mydb {
var $db = false;
var $error = false;
var $debug = true;
var $dbf = false;
var $database = false;
function mydb($host,$db,$user,$pass,$port,$proto,$error,$debug) {
$this->error = $error;
$dsn = array('phptype' => $proto,
'username' => $user,
'password' => $pass,
'hostspec' => $host,
'database' => $db,
'port' => $port);
$this->debug = $debug;
$this->database = "-< $db >-";
$this->connect($dsn);
}
function connect($dsn) {
$options = array('result_buffering' => false,);
$this->db = MDB2::connect($dsn,$options);
if ( $this->debug ) $this->error->write('dblib->connect '.$this->database,'Connect:');
if (PEAR::isError($this->db)) {
$this->error->write('dblib->connect '.$this->database,$this->db->getMessage());
$this->error->write('dblib->connect '.$this->database,print_r($dsn,true));
$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);
if ( $this->debug ) $this->error->write('dblib->getAll '.$this->database,$sql);
if (PEAR::isError($rs)) {
$this->error->write('dblib->getAll '.$this->database,$rs->getUserinfo());
return false;
}
return $rs;
}
function getOne($sql) {
$rs = $this->db->queryRow($sql);
if ( $this->debug ) $this->error->write('dblib->getOne '.$this->database,$sql);
if (PEAR::isError($rs)) {
$this->error->write('dblib->getOne '.$this->database,$rs->getUserinfo());
return false;
}
return $rs;
}
function query($sql) {
$rc = $this->db->query($sql);
if ( $this->debug ) $this->error->write('dblib->query '.$this->database,$sql);
if (PEAR::isError($rc)) {
$this->error->write('dblib->query '.$this->database,$rc->getUserinfo());
return false;
}
return $rc;
}
function insert($statement,$data) {
if ( $this->debug ) $this->error->write("dblib->insert ".$this->database,$statement);
$sth = $this->db->prepare($statement); //Prepare
if (PEAR::isError($sth)) {
$this->error->write('dblib->insert 1 '.$this->database,$sth->getMessage());
$this->error->write('dblib->insert 2',$sth->getUserinfo());
$this->rollback();
return false;
}
if ( $this->debug ) $this->error->write('dblib->insert',print_r($data,true));
$rc =& $sth->execute($data);
if (PEAR::isError($rc)) {
$this->error->write('dblib->insert 3 '.$this->database,$rc->getUserinfo());
return false;
}//else{
// $rc = $this->commit();
//}
return $rc;
}
function update($statement,$data) {
if ( $this->debug ) $this->error->write("dblib->update ".$this->database,$statement);
$sth = $this->db->prepare($statement); //Prepare
if (PEAR::isError($sth)) {
$this->error->write('dblib->update 1 '.$this->database,$sth->getMessage());
$this->error->write('dblib->update 2',$sth->getUserinfo());
$this->rollback();
return false;
}
if ( $this->debug ) $this->error->write('dblib->update',print_r($data,true));
$rc =& $sth->execute($data);
if (PEAR::isError($rc)) {
$this->error->write('dblib->update 3 '.$this->database,$rc->getUserinfo());
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)) {
$this->error->write('dblib->insertMultiple '.$this->database,$sth->getMessage());
$this->rollback();
return false;
}
$rc =& $this->db->beginTransaction();
$rc =& $this->db->extended->executeMultiple($sth, $data);
if (PEAR::isError($rc)) {
$this->error->write('dblib->insertMultiple '.$this->database,$rc->getUserinfo());
$this->rollback();
return false;
}else{
$rc = $this->commit();
}
return $rc;
}
}
?>