-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpudlShell.php
More file actions
137 lines (88 loc) · 3.56 KB
/
pudlShell.php
File metadata and controls
137 lines (88 loc) · 3.56 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
if (!class_exists('pudl',false)) require_once(__DIR__.'/../pudl.php');
require_once(is_owner(__DIR__.'/pudlShellResult.php'));
class pudlShell
extends pudl {
////////////////////////////////////////////////////////////////////////////
// CONSTRUCTOR
////////////////////////////////////////////////////////////////////////////
public function __construct($options) {
parent::__construct($options);
$this->path = empty($options['path']) ? '' : $options['path'];
}
////////////////////////////////////////////////////////////////////////////
// DESTRUCTOR
////////////////////////////////////////////////////////////////////////////
public function __destruct() {
$this->disconnect();
parent::__destruct();
}
////////////////////////////////////////////////////////////////////////////
// VERIFY WE HAVE THE PROPER PHP EXTENSION INSTALLED
// NOTE: NO ACTIVE CONNECTIONS ARE MADE WITH THIS UNTIL A REQUEST IS MADE
////////////////////////////////////////////////////////////////////////////
public function connect() {
pudl_require_extension('json');
}
////////////////////////////////////////////////////////////////////////////
// PERFORMS A QUERY ON THE DATABASE AND RETURNS A PUDLRESULT
// http://php.net/manual/en/function.exec.php
////////////////////////////////////////////////////////////////////////////
protected function process($query) {
$result = false;
exec(implode(' ', [
'php',
escapeshellarg($this->path),
escapeshellarg($query),
]), $result);
return $this->_process($result[0]);
}
////////////////////////////////////////////////////////////////////////////
// CREATE THE PUDLRESULT FROM JSON DATA AND RETURN IT
////////////////////////////////////////////////////////////////////////////
protected function _process($json) {
$item = new pudlShellResult($this, $json);
$this->insertId = $item->insertId();
$this->updated = $item->updated();
$this->errno = $item->errno();
$this->error = $this->errno ? $item->error() : '';
return $item;
}
////////////////////////////////////////////////////////////////////////////
// RETURNS THE AUTO GENERATED ID USED IN THE LATEST QUERY
////////////////////////////////////////////////////////////////////////////
public function insertId() {
return $this->insertId;
}
////////////////////////////////////////////////////////////////////////////
// GETS THE NUMBER OF AFFECTED ROWS IN A PREVIOUS MYSQL OPERATION
////////////////////////////////////////////////////////////////////////////
public function updated() {
return $this->updated;
}
////////////////////////////////////////////////////////////////////////////
// RETURNS THE ERROR CODE FOR THE MOST RECENT FUNCTION CALL
////////////////////////////////////////////////////////////////////////////
public function errno() {
return $this->errno;
}
////////////////////////////////////////////////////////////////////////////
// RETURNS A STRING DESCRIPTION OF THE LAST ERROR
////////////////////////////////////////////////////////////////////////////
public function error() {
global $__json_errors__;
if (!empty($this->error)) return $this->error;
$error = $this->errno();
return isset($__json_errors__[$error])
? $__json_errors__[$error]
: $__json_errors__[-1];
}
////////////////////////////////////////////////////////////////////////////
// MEMBER VARIABLES
////////////////////////////////////////////////////////////////////////////
protected $path = '';
protected $errno = false;
protected $error = false;
protected $insertId = 0;
protected $updated = 0;
}