-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpudlWeb.php
More file actions
84 lines (53 loc) · 2.11 KB
/
pudlWeb.php
File metadata and controls
84 lines (53 loc) · 2.11 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
<?php
if (!class_exists('pudl',false)) require_once(__DIR__.'/../pudl.php');
require_once(is_owner(__DIR__.'/pudlShellResult.php'));
class pudlWeb
extends pudlShell {
////////////////////////////////////////////////////////////////////////////
// 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('curl');
parent::connect();
}
////////////////////////////////////////////////////////////////////////////
// PERFORMS A QUERY ON THE DATABASE AND RETURNS A PUDLRESULT
////////////////////////////////////////////////////////////////////////////
protected function process($query) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $this->path,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => ['q' => $query],
CURLOPT_RETURNTRANSFER => true,
]);
$result = curl_exec($ch);
$this->curl_error = curl_error($ch);
$this->curl_errno = curl_errno($ch);
curl_close($ch);
return $this->_process($result);
}
////////////////////////////////////////////////////////////////////////////
// RETURNS THE ERROR CODE FOR THE MOST RECENT FUNCTION CALL
// http://php.net/manual/en/function.curl-errno.php
////////////////////////////////////////////////////////////////////////////
public function errno() {
return ($this->curl_errno)
? $this->curl_errno
: parent::errno();
}
////////////////////////////////////////////////////////////////////////////
// RETURNS A STRING DESCRIPTION OF THE LAST ERROR
// http://php.net/manual/en/function.curl-error.php
////////////////////////////////////////////////////////////////////////////
public function error() {
if ($this->curl_error) return $this->curl_error;
return parent::error();
}
////////////////////////////////////////////////////////////////////////////
// MEMBER VARIABLES
////////////////////////////////////////////////////////////////////////////
private $curl_errno = 0;
private $curl_error = '';
}