forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbclass.inc.php
57 lines (46 loc) · 1.01 KB
/
dbclass.inc.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
<?php
class DB {
public static $sql='';
function query($sql){
global $dbh;
self::$sql=$sql;
return $dbh->query($sql);
}
function exec($sql){
global $dbh;
self::$sql=$sql;
return $dbh->exec($sql);
}
function prepare($sql){
global $dbh;
self::$sql=$sql;
return $dbh->prepare($sql);
}
function lastInsertId() {
global $dbh;
return $dbh->lastInsertId();
}
function errorInfo() {
global $dbh;
return $dbh->errorInfo();
}
function errorCode(){
$msg=self::errorInfo();
return $msg[0];
}
function errorMessage(){
$msg=self::errorInfo();
return $msg[2];
}
// Pass the sql to include it with the output
function logError(){
global $dbh;
$trace=debug_backtrace();
$caller=(isset($trace[1]))?$trace[1]:array('function' => 'direct');
$function=$caller['function'];
$class=($function=='direct')?'direct':$caller['class'];
$sqloutput=(self::$sql)?" SQL=".self::$sql:'';
error_log("PDO Error $class::$function ".self::errorCode().":".self::errorMessage().$sqloutput);
}
}
?>