-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlitedal.php
More file actions
82 lines (68 loc) · 2.36 KB
/
Copy pathsqlitedal.php
File metadata and controls
82 lines (68 loc) · 2.36 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
<?php
class sqlitedal {
public $dbh;
private $statement;
/*
function __construct($username, $password, $hostname, $defaultDatabase) {
try {
$this->dbh = new PDO("mysql:host=$hostname;dbname=$defaultDatabase", $username, $password);
}
catch(PDOException $e) {
LogEvent("EMERGENCY", $e); #DB is down is bad obviously
$this->dbh = false;
}
}*/
function __construct($db) {
$this->dbh = $db;
}
function w($query, $preparedArray = null) {
return $this->write($query, $preparedArray);
}
function r($query, $preparedArray = null, $fetchMode=PDO::FETCH_ASSOC) {
return $this->read($query, $preparedArray, $fetchMode);
}
function rows_affected() {
return $this->statement->rowCount();
}
function write($query, $preparedArray = null) {
if($this->dbh === false) {
return false;
}
try {
$this->statement = $this->dbh->prepare($query);
if($preparedArray == null)
$this->statement->execute();
else {
$this->statement->execute($preparedArray);
#echo "<h1>E: ";
#print_r($this->dbh->errorInfo());
#echo "</h1>";
}
return true;
}
catch(PDOException $e) {
if(DEBUG)
echo $e."<BR />";
return false;
}
}
// This eventually needs cache, read/write splitting logic
function read($query, $preparedArray = null, $fetchMode=PDO::FETCH_ASSOC) {
if($this->dbh === false) {
return false;
}
try {
$this->statement = $this->dbh->prepare($query);
if($preparedArray == null)
$this->statement->execute();
else
$this->statement->execute($preparedArray);
return $this->statement->fetchAll($fetchMode);
}
catch(PDOException $e) {
if(DEBUG)
echo $e."<BR />";
return false;
}
}
}