-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintDB.php
More file actions
executable file
·121 lines (100 loc) · 2.31 KB
/
intDB.php
File metadata and controls
executable file
·121 lines (100 loc) · 2.31 KB
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
<?php
class IntDB
{
private $pdo_conn_string = "pgsql:host=localhost port=5434 dbname=postgres user=postgres password=secret";
private $counter = 0;
public function pdo_db_connect()
{
try
{
$pdo = @new PDO($this->pdo_conn_string);
}
catch (RuntimeException $e)
{
$GLOBALS["error"]= $e->getMessage();
return null;
}
return $pdo;
}
public function pdo_db_prepare($pdo,$query)
{
return $pdo->prepare($query);
}
public function pdo_db_bindValue(&$pQuery, $name, $value)
{
$pQuery->bindValue(":" . $name, $value);
return;
}
public function pdo_db_bindValueBool(&$pQuery, $name, $value)
{
$pQuery->bindValue(":" . $name, $value, PDO::PARAM_BOOL);
return;
}
public function pdo_db_bindValueString(&$pQuery, $name, $value)
{
$pQuery->bindValue(":" . $name, $value, PDO::PARAM_STR);
return;
}
public function pdo_db_query($pQuery)
{
return $pQuery->execute();
}
public function pdo_db_fetch($pQuery)
{
return $pQuery->fetch(PDO::FETCH_NUM);
}
public function pdo_db_fetch_assoc($pQuery)
{
return $pQuery->fetch(PDO::FETCH_ASSOC);
}
public function pdo_db_fetch_all($pQuery)
{
return $pQuery->fetchAll(PDO::FETCH_ASSOC);
}
public function pdo_db_columnCount($pQuery)
{
return $pQuery->columnCount();
}
public function pdo_db_beginTransaction($pdo)
{
if (!$this->counter++)
{
return $pdo->beginTransaction();
}
$query = "SAVEPOINT trans" . $this->counter;
$pQuery = $this->pdo_db_prepare($pdo, $query);
$this->pdo_db_query($pQuery);
return $this->counter >= 0;
}
public function pdo_db_rollBack($pdo)
{
if (--$this->counter)
{
$query = "ROLLBACK TO trans" . $this->counter;
$pQuery = $this->pdo_db_prepare($pdo, $query);
$this->pdo_db_query($pQuery);
return true;
}
return $pdo->rollBack();
}
public function pdo_db_commit($pdo)
{
if (!--$this->counter)
{
return $pdo->commit();
}
return $this->counter >= 0;
}
public function pdo_db_showErrors(&$pQuery)
{
$arr = $pQuery->errorInfo();
print_r($arr);
return;
}
public function pdo_db_rowCount($pQuery)
{
$count = $pQuery->rowCount();
return $count;
}
}
?>