-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.class.php
41 lines (35 loc) · 1.06 KB
/
db.class.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
<?php
require_once("config.inc.php");
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of api
*
* @author flohw
*/
class DB extends PDO {
private static $db = null;
public static function getDb() {
if(self::$db === null) {
self::$db = new DB();
}
return self::$db;
}
public function __construct($options = null) {
parent::__construct('mysql:host='.dbhost.';dbname='.dbname,
dbuser,
dbpw, $options);
parent::setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
public function safeQuery($query) {
$args = func_get_args();
array_shift($args); //first element is not an argument but the query itself, should get removed
$reponse = parent::prepare($query);
$reponse->execute($args);
return $reponse;
}
}