-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.php
executable file
·78 lines (53 loc) · 1.63 KB
/
database.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
<?php
/**
* Parameters for connecting to the database.
*/
/**
* Quick class for handling the database connection and queries.
* This is very much a bare bones class.
*/
class Database{
var $handle;
var $dsn;
var $pdo;
var $output_file;
public function __construct($engine, $host, $user, $pw, $db , $port, &$output_file){
$this->dsn = $engine . ':dbname=' . $db . ';host=' . $host . ';port=' . $port;
$this->pdo = new PDO($this->dsn, $user, $pw);
$this->output_file = $output_file;
}
public function runQuery($query){
try{
$this->output_file->write($query);
$result = $this->pdo->exec($query);
return $result;
}catch(Exception $ex){
$this->output_file("Exception occurred with query: " . $query);
$this->output_file->write(var_export($ex));
$this->rollback();
return false;
}
}
public function getResults($qry){
// $this->output_file->write($qry);
$query = $this->pdo->prepare($qry);
$query->execute();
return $query;
}
public function getId(){
return $this->pdo->lastInsertId();
}
public function close(){
//$this->output_file->close();
}
public function beginTransaction(){
$this->pdo->beginTransaction();
}
public function rollback(){
$this->pdo->rollBack();
}
public function commit(){
$this->pdo->commit();
}
}
?>