-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlib.pdo.php
More file actions
83 lines (67 loc) · 1.39 KB
/
lib.pdo.php
File metadata and controls
83 lines (67 loc) · 1.39 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
83
<?php
/**
* PDO wrapper class
*/
class Db {
/**
* The handle to the database connection
*/
private static $_conn = null;
/**
* The value of the last error message
*/
public static $lastError = '';
/**
* Opens a connection to the database
*/
public static function Connect($dsn, $user = '', $pass = '')
{
$retVal = false;
try {
self::$_conn = new PDO($dsn, $user, $pass);
$retVal = true;
} catch (PDOException $e) {
self::$lastError = $e->Message();
}
return $retVal;
}
/**
* Executes a query
*/
public static function Query($sql, $params = null)
{
$retVal = null;
try {
$comm = self::$_conn->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$comm->execute($params);
switch (strtolower(substr($sql, 0, 6))) {
case 'select':
$retVal = new stdClass();
$retVal->count = $comm->rowCount();
$retVal->comm = $comm;
break;
case 'insert':
$retVal = self::$_conn->lastInsertId();
break;
case 'update':
case 'delete':
$retVal = $comm->rowCount();
break;
}
} catch (PDOException $e) {
self::$lastError = $e->Message();
}
return $retVal;
}
/**
* Fetches the next row in a record set
*/
public static function Fetch($rs)
{
$retVal = null;
if (is_object($rs) && null != $rs->comm) {
$retVal = $rs->comm->fetchObject();
}
return $retVal;
}
}