-
-
Notifications
You must be signed in to change notification settings - Fork 573
/
_pdo.php
89 lines (87 loc) · 1.96 KB
/
_pdo.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
79
80
81
82
83
84
85
86
87
88
89
<?php
// PDO helper functions.
// Copyright (c) 2012-2014 The PHP Desktop authors. All rights reserved.
// License: New BSD License.
// Website: http://code.google.com/p/phpdesktop/
function PDO_Connect($dsn, $user="", $password="")
{
global $PDO;
$PDO = new PDO($dsn, $user, $password);
$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
}
function PDO_FetchOne($query, $params=null)
{
global $PDO;
if (isset($params)) {
$stmt = $PDO->prepare($query);
$stmt->execute($params);
} else {
$stmt = $PDO->query($query);
}
$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
return $row[0];
} else {
return false;
}
}
function PDO_FetchRow($query, $params=null)
{
global $PDO;
if (isset($params)) {
$stmt = $PDO->prepare($query);
$stmt->execute($params);
} else {
$stmt = $PDO->query($query);
}
return $stmt->fetch(PDO::FETCH_ASSOC);
}
function PDO_FetchAll($query, $params=null)
{
global $PDO;
if (isset($params)) {
$stmt = $PDO->prepare($query);
$stmt->execute($params);
} else {
$stmt = $PDO->query($query);
}
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
function PDO_FetchAssoc($query, $params=null)
{
global $PDO;
if (isset($params)) {
$stmt = $PDO->prepare($query);
$stmt->execute($params);
} else {
$stmt = $PDO->query($query);
}
$rows = $stmt->fetchAll(PDO::FETCH_NUM);
$assoc = array();
foreach ($rows as $row) {
$assoc[$row[0]] = $row[1];
}
return $assoc;
}
function PDO_Execute($query, $params=null)
{
global $PDO;
if (isset($params)) {
$stmt = $PDO->prepare($query);
$stmt->execute($params);
return $stmt;
} else {
return $PDO->query($query);
}
}
function PDO_LastInsertId()
{
global $PDO;
return $PDO->lastInsertId();
}
function PDO_ErrorInfo()
{
global $PDO;
return $PDO->errorInfo();
}
?>