-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.php
More file actions
67 lines (58 loc) · 1.17 KB
/
Database.php
File metadata and controls
67 lines (58 loc) · 1.17 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
<?php
namespace Blog;
class Database {
/**
* Singleton-Instanz
*
* @var \Blog\Database
*/
protected static $_instance = null;
/**
* Get the Database-Object
*
* @return \Blog\Database
*/
public static function getInstance() {
if (null === self::$_instance) {
self::$_instance = new self();
}
return self::$_instance;
}
// Disable Cloning and external Construction
protected function __clone() {
}
/**
*
* @var \PDO
*/
private $dbh;
protected function __construct() {
$config = Config::getInstance();
$this->dbh = new \PDO($config->DBConnectionString, $config->DBUsername, $config->DBPassword);
}
/**
* Prepares an SQL Statement
*
* @param String $sql
* The SQL Text to be prepared
* @return \PDOStatement
*/
public function prepare(String $sql) {
return $this->dbh->prepare($sql);
}
/**
* Query an SQL Statement
* @param String $sql
* @return \PDOStatement
*/
public function query(String $sql) {
return $this->dbh->query($sql);
}
/**
* Returns the ID of the last inserted row or sequence value
* @return int
*/
public function lastInsertId() {
return $this->dbh->lastInsertId();
}
}