@@ -155,6 +155,10 @@ |
||
155 | 155 | |
156 | 156 | |
157 | 157 | // returns query ID if successful, otherwise false |
158 | + |
|
159 | + /** |
|
160 | + * @param string $sql |
|
161 | + */ |
|
158 | 162 | function _query($sql,$inputarr=false) |
159 | 163 | { |
160 | 164 | // <G. Giunta 2003/03/03/> Reset error messages before executing |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | /* there seems to be a bug in the oracle extension -- always returns ORA-00000 - no error */ |
76 | 76 | function ErrorMsg() |
77 | 77 | { |
78 | - if ($this->_errorMsg !== false) return $this->_errorMsg; |
|
78 | + if ($this->_errorMsg !== false) return $this->_errorMsg; |
|
79 | 79 | |
80 | - if (is_resource($this->_curs)) $this->_errorMsg = @ora_error($this->_curs); |
|
80 | + if (is_resource($this->_curs)) $this->_errorMsg = @ora_error($this->_curs); |
|
81 | 81 | if (empty($this->_errorMsg)) $this->_errorMsg = @ora_error($this->_connectionID); |
82 | 82 | return $this->_errorMsg; |
83 | 83 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | |
90 | 90 | if (is_resource($this->_curs)) $this->_errorCode = @ora_errorcode($this->_curs); |
91 | 91 | if (empty($this->_errorCode)) $this->_errorCode = @ora_errorcode($this->_connectionID); |
92 | - return $this->_errorCode; |
|
92 | + return $this->_errorCode; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | { |
100 | 100 | if (!function_exists('ora_plogon')) return null; |
101 | 101 | |
102 | - // <G. Giunta 2003/03/03/> Reset error messages before connecting |
|
103 | - $this->_errorMsg = false; |
|
104 | - $this->_errorCode = false; |
|
102 | + // <G. Giunta 2003/03/03/> Reset error messages before connecting |
|
103 | + $this->_errorMsg = false; |
|
104 | + $this->_errorCode = false; |
|
105 | 105 | |
106 | - // G. Giunta 2003/08/13 - This looks danegrously suspicious: why should we want to set |
|
107 | - // the oracle home to the host name of remote DB? |
|
106 | + // G. Giunta 2003/08/13 - This looks danegrously suspicious: why should we want to set |
|
107 | + // the oracle home to the host name of remote DB? |
|
108 | 108 | // if ($argHostname) putenv("ORACLE_HOME=$argHostname"); |
109 | 109 | |
110 | 110 | if($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen <[email protected]> |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | // returns query ID if successful, otherwise false |
158 | 158 | function _query($sql,$inputarr=false) |
159 | 159 | { |
160 | - // <G. Giunta 2003/03/03/> Reset error messages before executing |
|
161 | - $this->_errorMsg = false; |
|
162 | - $this->_errorCode = false; |
|
160 | + // <G. Giunta 2003/03/03/> Reset error messages before executing |
|
161 | + $this->_errorMsg = false; |
|
162 | + $this->_errorCode = false; |
|
163 | 163 | |
164 | 164 | $curs = ora_open($this->_connectionID); |
165 | 165 | |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | $this->_curs = $curs; |
168 | 168 | if (!ora_parse($curs,$sql)) return false; |
169 | 169 | if (ora_exec($curs)) return $curs; |
170 | - // <G. Giunta 2004/03/03> before we close the cursor, we have to store the error message |
|
171 | - // that we can obtain ONLY from the cursor (and not from the connection) |
|
172 | - $this->_errorCode = @ora_errorcode($curs); |
|
173 | - $this->_errorMsg = @ora_error($curs); |
|
174 | - // </G. Giunta 2004/03/03> |
|
170 | + // <G. Giunta 2004/03/03> before we close the cursor, we have to store the error message |
|
171 | + // that we can obtain ONLY from the cursor (and not from the connection) |
|
172 | + $this->_errorCode = @ora_errorcode($curs); |
|
173 | + $this->_errorMsg = @ora_error($curs); |
|
174 | + // </G. Giunta 2004/03/03> |
|
175 | 175 | @ora_close($curs); |
176 | 176 | return false; |
177 | 177 | } |
@@ -290,30 +290,30 @@ |
||
290 | 290 | } |
291 | 291 | |
292 | 292 | switch (strtoupper($t)) { |
293 | - case 'VARCHAR': |
|
294 | - case 'VARCHAR2': |
|
295 | - case 'CHAR': |
|
296 | - case 'VARBINARY': |
|
297 | - case 'BINARY': |
|
298 | - if ($len <= $this->blobSize) return 'C'; |
|
299 | - case 'LONG': |
|
300 | - case 'LONG VARCHAR': |
|
301 | - case 'CLOB': |
|
302 | - return 'X'; |
|
303 | - case 'LONG RAW': |
|
304 | - case 'LONG VARBINARY': |
|
305 | - case 'BLOB': |
|
306 | - return 'B'; |
|
293 | + case 'VARCHAR': |
|
294 | + case 'VARCHAR2': |
|
295 | + case 'CHAR': |
|
296 | + case 'VARBINARY': |
|
297 | + case 'BINARY': |
|
298 | + if ($len <= $this->blobSize) return 'C'; |
|
299 | + case 'LONG': |
|
300 | + case 'LONG VARCHAR': |
|
301 | + case 'CLOB': |
|
302 | + return 'X'; |
|
303 | + case 'LONG RAW': |
|
304 | + case 'LONG VARBINARY': |
|
305 | + case 'BLOB': |
|
306 | + return 'B'; |
|
307 | 307 | |
308 | - case 'DATE': return 'D'; |
|
308 | + case 'DATE': return 'D'; |
|
309 | 309 | |
310 | - //case 'T': return 'T'; |
|
310 | + //case 'T': return 'T'; |
|
311 | 311 | |
312 | - case 'BIT': return 'L'; |
|
313 | - case 'INT': |
|
314 | - case 'SMALLINT': |
|
315 | - case 'INTEGER': return 'I'; |
|
316 | - default: return 'N'; |
|
312 | + case 'BIT': return 'L'; |
|
313 | + case 'INT': |
|
314 | + case 'SMALLINT': |
|
315 | + case 'INTEGER': return 'I'; |
|
316 | + default: return 'N'; |
|
317 | 317 | } |
318 | 318 | } |
319 | 319 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | class ADODB_oracle extends ADOConnection { |
19 | 19 | var $databaseType = "oracle"; |
20 | 20 | var $replaceQuote = "''"; // string to use to replace quotes |
21 | - var $concat_operator='||'; |
|
21 | + var $concat_operator = '||'; |
|
22 | 22 | var $_curs; |
23 | 23 | var $_initdate = true; // init date to YYYY-MM-DD |
24 | 24 | var $metaTablesSQL = 'select table_name from cat'; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | function DBDate($d) |
36 | 36 | { |
37 | 37 | if (is_string($d)) $d = ADORecordSet::UnixDate($d); |
38 | - return 'TO_DATE('.adodb_date($this->fmtDate,$d).",'YYYY-MM-DD')"; |
|
38 | + return 'TO_DATE('.adodb_date($this->fmtDate, $d).",'YYYY-MM-DD')"; |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | // format and return date string in database timestamp format |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | { |
44 | 44 | |
45 | 45 | if (is_string($ts)) $d = ADORecordSet::UnixTimeStamp($ts); |
46 | - return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')"; |
|
46 | + return 'TO_DATE('.adodb_date($this->fmtTimeStamp, $ts).",'RRRR-MM-DD, HH:MI:SS AM')"; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | } |
56 | 56 | |
57 | 57 | |
58 | - function CommitTrans($ok=true) |
|
58 | + function CommitTrans($ok = true) |
|
59 | 59 | { |
60 | 60 | if (!$ok) return $this->RollbackTrans(); |
61 | 61 | $ret = ora_commit($this->_connectionID); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | |
97 | 97 | // returns true or false |
98 | - function _connect($argHostname, $argUsername, $argPassword, $argDatabasename, $mode=0) |
|
98 | + function _connect($argHostname, $argUsername, $argPassword, $argDatabasename, $mode = 0) |
|
99 | 99 | { |
100 | 100 | if (!function_exists('ora_plogon')) return null; |
101 | 101 | |
@@ -107,23 +107,23 @@ discard block |
||
107 | 107 | // the oracle home to the host name of remote DB? |
108 | 108 | // if ($argHostname) putenv("ORACLE_HOME=$argHostname"); |
109 | 109 | |
110 | - if($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen <[email protected]> |
|
110 | + if ($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen <[email protected]> |
|
111 | 111 | if (empty($argDatabasename)) $argDatabasename = $argHostname; |
112 | 112 | else { |
113 | - if(strpos($argHostname,":")) { |
|
114 | - $argHostinfo=explode(":",$argHostname); |
|
115 | - $argHostname=$argHostinfo[0]; |
|
116 | - $argHostport=$argHostinfo[1]; |
|
113 | + if (strpos($argHostname, ":")) { |
|
114 | + $argHostinfo = explode(":", $argHostname); |
|
115 | + $argHostname = $argHostinfo[0]; |
|
116 | + $argHostport = $argHostinfo[1]; |
|
117 | 117 | } else { |
118 | - $argHostport="1521"; |
|
118 | + $argHostport = "1521"; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | |
122 | 122 | if ($this->connectSID) { |
123 | - $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
123 | + $argDatabasename = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
124 | 124 | .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))"; |
125 | 125 | } else |
126 | - $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
126 | + $argDatabasename = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
127 | 127 | .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))"; |
128 | 128 | } |
129 | 129 | |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | |
134 | 134 | //if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>"; |
135 | 135 | if ($mode = 1) |
136 | - $this->_connectionID = ora_plogon($argUsername,$argPassword); |
|
136 | + $this->_connectionID = ora_plogon($argUsername, $argPassword); |
|
137 | 137 | else |
138 | - $this->_connectionID = ora_logon($argUsername,$argPassword); |
|
138 | + $this->_connectionID = ora_logon($argUsername, $argPassword); |
|
139 | 139 | if ($this->_connectionID === false) return false; |
140 | 140 | if ($this->autoCommit) ora_commiton($this->_connectionID); |
141 | 141 | if ($this->_initdate) { |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | |
156 | 156 | |
157 | 157 | // returns query ID if successful, otherwise false |
158 | - function _query($sql,$inputarr=false) |
|
158 | + function _query($sql, $inputarr = false) |
|
159 | 159 | { |
160 | 160 | // <G. Giunta 2003/03/03/> Reset error messages before executing |
161 | 161 | $this->_errorMsg = false; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | |
166 | 166 | if ($curs === false) return false; |
167 | 167 | $this->_curs = $curs; |
168 | - if (!ora_parse($curs,$sql)) return false; |
|
168 | + if (!ora_parse($curs, $sql)) return false; |
|
169 | 169 | if (ora_exec($curs)) return $curs; |
170 | 170 | // <G. Giunta 2004/03/03> before we close the cursor, we have to store the error message |
171 | 171 | // that we can obtain ONLY from the cursor (and not from the connection) |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | var $databaseType = "oracle"; |
198 | 198 | var $bind = false; |
199 | 199 | |
200 | - function ADORecordset_oracle($queryID,$mode=false) |
|
200 | + function ADORecordset_oracle($queryID, $mode = false) |
|
201 | 201 | { |
202 | 202 | |
203 | 203 | if ($mode === false) { |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | { |
245 | 245 | if (!$this->bind) { |
246 | 246 | $this->bind = array(); |
247 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
247 | + for ($i = 0; $i < $this->_numOfFields; $i++) { |
|
248 | 248 | $o = $this->FetchField($i); |
249 | 249 | $this->bind[strtoupper($o->name)] = $i; |
250 | 250 | } |
@@ -265,12 +265,12 @@ discard block |
||
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
268 | - function _fetch($ignore_fields=false) { |
|
268 | + function _fetch($ignore_fields = false) { |
|
269 | 269 | // should remove call by reference, but ora_fetch_into requires it in 4.0.3pl1 |
270 | - if ($this->fetchMode & ADODB_FETCH_ASSOC) |
|
271 | - return @ora_fetch_into($this->_queryID,&$this->fields,ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC); |
|
270 | + if ($this->fetchMode&ADODB_FETCH_ASSOC) |
|
271 | + return @ora_fetch_into($this->_queryID, &$this->fields, ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC); |
|
272 | 272 | else |
273 | - return @ora_fetch_into($this->_queryID,&$this->fields,ORA_FETCHINTO_NULLS); |
|
273 | + return @ora_fetch_into($this->_queryID, &$this->fields, ORA_FETCHINTO_NULLS); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /* close() only needs to be called if you are worried about using too much memory while your script |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | return @ora_close($this->_queryID); |
282 | 282 | } |
283 | 283 | |
284 | - function MetaType($t,$len=-1) |
|
284 | + function MetaType($t, $len = -1) |
|
285 | 285 | { |
286 | 286 | if (is_object($t)) { |
287 | 287 | $fieldobj = $t; |
@@ -13,9 +13,13 @@ discard block |
||
13 | 13 | */ |
14 | 14 | |
15 | 15 | // security - hide paths |
16 | -if (!defined('ADODB_DIR')) die(); |
|
16 | +if (!defined('ADODB_DIR')) |
|
17 | +{ |
|
18 | + die(); |
|
19 | +} |
|
17 | 20 | |
18 | -class ADODB_oracle extends ADOConnection { |
|
21 | +class ADODB_oracle extends ADOConnection |
|
22 | +{ |
|
19 | 23 | var $databaseType = "oracle"; |
20 | 24 | var $replaceQuote = "''"; // string to use to replace quotes |
21 | 25 | var $concat_operator='||'; |
@@ -27,14 +31,17 @@ discard block |
||
27 | 31 | var $sysTimeStamp = 'SYSDATE'; |
28 | 32 | var $connectSID = true; |
29 | 33 | |
30 | - function ADODB_oracle() |
|
34 | + function ADODB_oracle() |
|
31 | 35 | { |
32 | 36 | } |
33 | 37 | |
34 | 38 | // format and return date string in database date format |
35 | 39 | function DBDate($d) |
36 | 40 | { |
37 | - if (is_string($d)) $d = ADORecordSet::UnixDate($d); |
|
41 | + if (is_string($d)) |
|
42 | + { |
|
43 | + $d = ADORecordSet::UnixDate($d); |
|
44 | + } |
|
38 | 45 | return 'TO_DATE('.adodb_date($this->fmtDate,$d).",'YYYY-MM-DD')"; |
39 | 46 | } |
40 | 47 | |
@@ -42,22 +49,28 @@ discard block |
||
42 | 49 | function DBTimeStamp($ts) |
43 | 50 | { |
44 | 51 | |
45 | - if (is_string($ts)) $d = ADORecordSet::UnixTimeStamp($ts); |
|
52 | + if (is_string($ts)) |
|
53 | + { |
|
54 | + $d = ADORecordSet::UnixTimeStamp($ts); |
|
55 | + } |
|
46 | 56 | return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')"; |
47 | 57 | } |
48 | 58 | |
49 | 59 | |
50 | 60 | function BeginTrans() |
51 | - { |
|
61 | + { |
|
52 | 62 | $this->autoCommit = false; |
53 | 63 | ora_commitoff($this->_connectionID); |
54 | 64 | return true; |
55 | 65 | } |
56 | 66 | |
57 | 67 | |
58 | - function CommitTrans($ok=true) |
|
59 | - { |
|
60 | - if (!$ok) return $this->RollbackTrans(); |
|
68 | + function CommitTrans($ok=true) |
|
69 | + { |
|
70 | + if (!$ok) |
|
71 | + { |
|
72 | + return $this->RollbackTrans(); |
|
73 | + } |
|
61 | 74 | $ret = ora_commit($this->_connectionID); |
62 | 75 | ora_commiton($this->_connectionID); |
63 | 76 | return $ret; |
@@ -73,22 +86,40 @@ discard block |
||
73 | 86 | |
74 | 87 | |
75 | 88 | /* there seems to be a bug in the oracle extension -- always returns ORA-00000 - no error */ |
76 | - function ErrorMsg() |
|
77 | - { |
|
78 | - if ($this->_errorMsg !== false) return $this->_errorMsg; |
|
79 | - |
|
80 | - if (is_resource($this->_curs)) $this->_errorMsg = @ora_error($this->_curs); |
|
81 | - if (empty($this->_errorMsg)) $this->_errorMsg = @ora_error($this->_connectionID); |
|
89 | + function ErrorMsg() |
|
90 | + { |
|
91 | + if ($this->_errorMsg !== false) |
|
92 | + { |
|
93 | + return $this->_errorMsg; |
|
94 | + } |
|
95 | + |
|
96 | + if (is_resource($this->_curs)) |
|
97 | + { |
|
98 | + $this->_errorMsg = @ora_error($this->_curs); |
|
99 | + } |
|
100 | + if (empty($this->_errorMsg)) |
|
101 | + { |
|
102 | + $this->_errorMsg = @ora_error($this->_connectionID); |
|
103 | + } |
|
82 | 104 | return $this->_errorMsg; |
83 | 105 | } |
84 | 106 | |
85 | 107 | |
86 | - function ErrorNo() |
|
108 | + function ErrorNo() |
|
87 | 109 | { |
88 | - if ($this->_errorCode !== false) return $this->_errorCode; |
|
110 | + if ($this->_errorCode !== false) |
|
111 | + { |
|
112 | + return $this->_errorCode; |
|
113 | + } |
|
89 | 114 | |
90 | - if (is_resource($this->_curs)) $this->_errorCode = @ora_errorcode($this->_curs); |
|
91 | - if (empty($this->_errorCode)) $this->_errorCode = @ora_errorcode($this->_connectionID); |
|
115 | + if (is_resource($this->_curs)) |
|
116 | + { |
|
117 | + $this->_errorCode = @ora_errorcode($this->_curs); |
|
118 | + } |
|
119 | + if (empty($this->_errorCode)) |
|
120 | + { |
|
121 | + $this->_errorCode = @ora_errorcode($this->_connectionID); |
|
122 | + } |
|
92 | 123 | return $this->_errorCode; |
93 | 124 | } |
94 | 125 | |
@@ -97,7 +128,10 @@ discard block |
||
97 | 128 | // returns true or false |
98 | 129 | function _connect($argHostname, $argUsername, $argPassword, $argDatabasename, $mode=0) |
99 | 130 | { |
100 | - if (!function_exists('ora_plogon')) return null; |
|
131 | + if (!function_exists('ora_plogon')) |
|
132 | + { |
|
133 | + return null; |
|
134 | + } |
|
101 | 135 | |
102 | 136 | // <G. Giunta 2003/03/03/> Reset error messages before connecting |
103 | 137 | $this->_errorMsg = false; |
@@ -107,40 +141,68 @@ discard block |
||
107 | 141 | // the oracle home to the host name of remote DB? |
108 | 142 | // if ($argHostname) putenv("ORACLE_HOME=$argHostname"); |
109 | 143 | |
110 | - if($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen <[email protected]> |
|
111 | - if (empty($argDatabasename)) $argDatabasename = $argHostname; |
|
112 | - else { |
|
113 | - if(strpos($argHostname,":")) { |
|
144 | + if($argHostname) |
|
145 | + { |
|
146 | +// code copied from version submitted for oci8 by Jorma Tuomainen <[email protected]> |
|
147 | + if (empty($argDatabasename)) |
|
148 | + { |
|
149 | + $argDatabasename = $argHostname; |
|
150 | + } |
|
151 | + else |
|
152 | + { |
|
153 | + if(strpos($argHostname,":")) |
|
154 | + { |
|
114 | 155 | $argHostinfo=explode(":",$argHostname); |
115 | 156 | $argHostname=$argHostinfo[0]; |
116 | 157 | $argHostport=$argHostinfo[1]; |
117 | - } else { |
|
158 | + } |
|
159 | + else |
|
160 | + { |
|
118 | 161 | $argHostport="1521"; |
119 | 162 | } |
120 | 163 | |
121 | 164 | |
122 | - if ($this->connectSID) { |
|
165 | + if ($this->connectSID) |
|
166 | + { |
|
123 | 167 | $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
124 | 168 | .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))"; |
125 | - } else |
|
126 | - $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
169 | + } |
|
170 | + else { |
|
171 | + $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
127 | 172 | .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))"; |
173 | + } |
|
128 | 174 | } |
129 | 175 | |
130 | 176 | } |
131 | 177 | |
132 | - if ($argDatabasename) $argUsername .= "@$argDatabasename"; |
|
178 | + if ($argDatabasename) |
|
179 | + { |
|
180 | + $argUsername .= "@$argDatabasename"; |
|
181 | + } |
|
133 | 182 | |
134 | 183 | //if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>"; |
135 | 184 | if ($mode = 1) |
136 | - $this->_connectionID = ora_plogon($argUsername,$argPassword); |
|
137 | - else |
|
138 | - $this->_connectionID = ora_logon($argUsername,$argPassword); |
|
139 | - if ($this->_connectionID === false) return false; |
|
140 | - if ($this->autoCommit) ora_commiton($this->_connectionID); |
|
141 | - if ($this->_initdate) { |
|
185 | + { |
|
186 | + $this->_connectionID = ora_plogon($argUsername,$argPassword); |
|
187 | + } |
|
188 | + else { |
|
189 | + $this->_connectionID = ora_logon($argUsername,$argPassword); |
|
190 | + } |
|
191 | + if ($this->_connectionID === false) |
|
192 | + { |
|
193 | + return false; |
|
194 | + } |
|
195 | + if ($this->autoCommit) |
|
196 | + { |
|
197 | + ora_commiton($this->_connectionID); |
|
198 | + } |
|
199 | + if ($this->_initdate) |
|
200 | + { |
|
142 | 201 | $rs = $this->_query("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'"); |
143 | - if ($rs) ora_close($rs); |
|
202 | + if ($rs) |
|
203 | + { |
|
204 | + ora_close($rs); |
|
205 | + } |
|
144 | 206 | } |
145 | 207 | |
146 | 208 | return true; |
@@ -163,10 +225,19 @@ discard block |
||
163 | 225 | |
164 | 226 | $curs = ora_open($this->_connectionID); |
165 | 227 | |
166 | - if ($curs === false) return false; |
|
228 | + if ($curs === false) |
|
229 | + { |
|
230 | + return false; |
|
231 | + } |
|
167 | 232 | $this->_curs = $curs; |
168 | - if (!ora_parse($curs,$sql)) return false; |
|
169 | - if (ora_exec($curs)) return $curs; |
|
233 | + if (!ora_parse($curs,$sql)) |
|
234 | + { |
|
235 | + return false; |
|
236 | + } |
|
237 | + if (ora_exec($curs)) |
|
238 | + { |
|
239 | + return $curs; |
|
240 | + } |
|
170 | 241 | // <G. Giunta 2004/03/03> before we close the cursor, we have to store the error message |
171 | 242 | // that we can obtain ONLY from the cursor (and not from the connection) |
172 | 243 | $this->_errorCode = @ora_errorcode($curs); |
@@ -192,7 +263,8 @@ discard block |
||
192 | 263 | Class Name: Recordset |
193 | 264 | --------------------------------------------------------------------------------------*/ |
194 | 265 | |
195 | -class ADORecordset_oracle extends ADORecordSet { |
|
266 | +class ADORecordset_oracle extends ADORecordSet |
|
267 | +{ |
|
196 | 268 | |
197 | 269 | var $databaseType = "oracle"; |
198 | 270 | var $bind = false; |
@@ -200,7 +272,8 @@ discard block |
||
200 | 272 | function ADORecordset_oracle($queryID,$mode=false) |
201 | 273 | { |
202 | 274 | |
203 | - if ($mode === false) { |
|
275 | + if ($mode === false) |
|
276 | + { |
|
204 | 277 | global $ADODB_FETCH_MODE; |
205 | 278 | $mode = $ADODB_FETCH_MODE; |
206 | 279 | } |
@@ -210,11 +283,14 @@ discard block |
||
210 | 283 | |
211 | 284 | $this->_inited = true; |
212 | 285 | $this->fields = array(); |
213 | - if ($queryID) { |
|
286 | + if ($queryID) |
|
287 | + { |
|
214 | 288 | $this->_currentRow = 0; |
215 | 289 | $this->EOF = !$this->_fetch(); |
216 | 290 | @$this->_initrs(); |
217 | - } else { |
|
291 | + } |
|
292 | + else |
|
293 | + { |
|
218 | 294 | $this->_numOfRows = 0; |
219 | 295 | $this->_numOfFields = 0; |
220 | 296 | $this->EOF = true; |
@@ -242,9 +318,11 @@ discard block |
||
242 | 318 | /* Use associative array to get fields array */ |
243 | 319 | function Fields($colname) |
244 | 320 | { |
245 | - if (!$this->bind) { |
|
321 | + if (!$this->bind) |
|
322 | + { |
|
246 | 323 | $this->bind = array(); |
247 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
324 | + for ($i=0; $i < $this->_numOfFields; $i++) |
|
325 | + { |
|
248 | 326 | $o = $this->FetchField($i); |
249 | 327 | $this->bind[strtoupper($o->name)] = $i; |
250 | 328 | } |
@@ -265,37 +343,46 @@ discard block |
||
265 | 343 | return false; |
266 | 344 | } |
267 | 345 | |
268 | - function _fetch($ignore_fields=false) { |
|
346 | + function _fetch($ignore_fields=false) |
|
347 | + { |
|
269 | 348 | // should remove call by reference, but ora_fetch_into requires it in 4.0.3pl1 |
270 | 349 | if ($this->fetchMode & ADODB_FETCH_ASSOC) |
271 | - return @ora_fetch_into($this->_queryID,&$this->fields,ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC); |
|
272 | - else |
|
273 | - return @ora_fetch_into($this->_queryID,&$this->fields,ORA_FETCHINTO_NULLS); |
|
350 | + { |
|
351 | + return @ora_fetch_into($this->_queryID,&$this->fields,ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC); |
|
352 | + } |
|
353 | + else { |
|
354 | + return @ora_fetch_into($this->_queryID,&$this->fields,ORA_FETCHINTO_NULLS); |
|
355 | + } |
|
274 | 356 | } |
275 | 357 | |
276 | 358 | /* close() only needs to be called if you are worried about using too much memory while your script |
277 | 359 | is running. All associated result memory for the specified result identifier will automatically be freed. */ |
278 | 360 | |
279 | - function _close() |
|
280 | -{ |
|
361 | + function _close() |
|
362 | + { |
|
281 | 363 | return @ora_close($this->_queryID); |
282 | 364 | } |
283 | 365 | |
284 | 366 | function MetaType($t,$len=-1) |
285 | 367 | { |
286 | - if (is_object($t)) { |
|
368 | + if (is_object($t)) |
|
369 | + { |
|
287 | 370 | $fieldobj = $t; |
288 | 371 | $t = $fieldobj->type; |
289 | 372 | $len = $fieldobj->max_length; |
290 | 373 | } |
291 | 374 | |
292 | - switch (strtoupper($t)) { |
|
375 | + switch (strtoupper($t)) |
|
376 | + { |
|
293 | 377 | case 'VARCHAR': |
294 | 378 | case 'VARCHAR2': |
295 | 379 | case 'CHAR': |
296 | 380 | case 'VARBINARY': |
297 | 381 | case 'BINARY': |
298 | - if ($len <= $this->blobSize) return 'C'; |
|
382 | + if ($len <= $this->blobSize) |
|
383 | + { |
|
384 | + return 'C'; |
|
385 | + } |
|
299 | 386 | case 'LONG': |
300 | 387 | case 'LONG VARCHAR': |
301 | 388 | case 'CLOB': |
@@ -373,6 +373,9 @@ |
||
373 | 373 | var $_stmt; |
374 | 374 | var $_connectionID; |
375 | 375 | |
376 | + /** |
|
377 | + * @param ADODB_pdo $connection |
|
378 | + */ |
|
376 | 379 | function ADOPDOStatement($stmt,$connection) |
377 | 380 | { |
378 | 381 | $this->_stmt = $stmt; |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | function adodb_pdo_type($t) |
52 | 52 | { |
53 | 53 | switch($t) { |
54 | - case 2: return 'VARCHAR'; |
|
55 | - case 3: return 'BLOB'; |
|
56 | - default: return 'NUMERIC'; |
|
54 | + case 2: return 'VARCHAR'; |
|
55 | + case 3: return 'BLOB'; |
|
56 | + default: return 'NUMERIC'; |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | |
156 | 156 | if ($this->_connectionID) { |
157 | 157 | switch(ADODB_ASSOC_CASE){ |
158 | - case 0: $m = PDO_CASE_LOWER; break; |
|
159 | - case 1: $m = PDO_CASE_UPPER; break; |
|
160 | - default: |
|
161 | - case 2: $m = PDO_CASE_NATURAL; break; |
|
158 | + case 0: $m = PDO_CASE_LOWER; break; |
|
159 | + case 1: $m = PDO_CASE_UPPER; break; |
|
160 | + default: |
|
161 | + case 2: $m = PDO_CASE_NATURAL; break; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | //$this->_connectionID->setAttribute(PDO_ATTR_ERRMODE,PDO_ERRMODE_SILENT ); |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | $class = 'ADODB_pdo_'.$this->dsnType; |
168 | 168 | //$this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT,true); |
169 | 169 | switch($this->dsnType) { |
170 | - case 'oci': |
|
171 | - case 'mysql': |
|
172 | - case 'pgsql': |
|
173 | - include_once(ADODB_DIR.'/drivers/adodb-pdo_'.$this->dsnType.'.inc.php'); |
|
174 | - break; |
|
170 | + case 'oci': |
|
171 | + case 'mysql': |
|
172 | + case 'pgsql': |
|
173 | + include_once(ADODB_DIR.'/drivers/adodb-pdo_'.$this->dsnType.'.inc.php'); |
|
174 | + break; |
|
175 | 175 | } |
176 | 176 | if (class_exists($class)) |
177 | 177 | $this->_driver = new $class(); |
@@ -440,11 +440,11 @@ discard block |
||
440 | 440 | } |
441 | 441 | $this->adodbFetchMode = $mode; |
442 | 442 | switch($mode) { |
443 | - case ADODB_FETCH_NUM: $mode = PDO_FETCH_NUM; break; |
|
444 | - case ADODB_FETCH_ASSOC: $mode = PDO_FETCH_ASSOC; break; |
|
443 | + case ADODB_FETCH_NUM: $mode = PDO_FETCH_NUM; break; |
|
444 | + case ADODB_FETCH_ASSOC: $mode = PDO_FETCH_ASSOC; break; |
|
445 | 445 | |
446 | - case ADODB_FETCH_BOTH: |
|
447 | - default: $mode = PDO_FETCH_BOTH; break; |
|
446 | + case ADODB_FETCH_BOTH: |
|
447 | + default: $mode = PDO_FETCH_BOTH; break; |
|
448 | 448 | } |
449 | 449 | $this->fetchMode = $mode; |
450 | 450 |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | function adodb_pdo_type($t) |
52 | 52 | { |
53 | - switch($t) { |
|
53 | + switch ($t) { |
|
54 | 54 | case 2: return 'VARCHAR'; |
55 | 55 | case 3: return 'BLOB'; |
56 | 56 | default: return 'NUMERIC'; |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | return ADOConnection::ServerInfo(); |
78 | 78 | } |
79 | 79 | |
80 | - function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) |
|
80 | + function &SelectLimit($sql, $nrows = -1, $offset = -1, $inputarr = false, $secs2cache = 0) |
|
81 | 81 | { |
82 | - $ret = ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); |
|
82 | + $ret = ADOConnection::SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache); |
|
83 | 83 | return $ret; |
84 | 84 | } |
85 | 85 | |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | // returns true or false |
141 | - function _connect($argDSN, $argUsername, $argPassword, $argDatabasename, $persist=false) |
|
141 | + function _connect($argDSN, $argUsername, $argPassword, $argDatabasename, $persist = false) |
|
142 | 142 | { |
143 | - $at = strpos($argDSN,':'); |
|
144 | - $this->dsnType = substr($argDSN,0,$at); |
|
143 | + $at = strpos($argDSN, ':'); |
|
144 | + $this->dsnType = substr($argDSN, 0, $at); |
|
145 | 145 | |
146 | 146 | try { |
147 | 147 | $this->_connectionID = new PDO($argDSN, $argUsername, $argPassword); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | if ($this->_connectionID) { |
157 | - switch(ADODB_ASSOC_CASE){ |
|
157 | + switch (ADODB_ASSOC_CASE) { |
|
158 | 158 | case 0: $m = PDO_CASE_LOWER; break; |
159 | 159 | case 1: $m = PDO_CASE_UPPER; break; |
160 | 160 | default: |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | } |
163 | 163 | |
164 | 164 | //$this->_connectionID->setAttribute(PDO_ATTR_ERRMODE,PDO_ERRMODE_SILENT ); |
165 | - $this->_connectionID->setAttribute(PDO_ATTR_CASE,$m); |
|
165 | + $this->_connectionID->setAttribute(PDO_ATTR_CASE, $m); |
|
166 | 166 | |
167 | 167 | $class = 'ADODB_pdo_'.$this->dsnType; |
168 | 168 | //$this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT,true); |
169 | - switch($this->dsnType) { |
|
169 | + switch ($this->dsnType) { |
|
170 | 170 | case 'oci': |
171 | 171 | case 'mysql': |
172 | 172 | case 'pgsql': |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | /*------------------------------------------------------------------------------*/ |
196 | 196 | |
197 | 197 | |
198 | - function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) |
|
198 | + function &SelectLimit($sql, $nrows = -1, $offset = -1, $inputarr = false, $secs2cache = 0) |
|
199 | 199 | { |
200 | 200 | $save = $this->_driver->fetchMode; |
201 | 201 | $this->_driver->fetchMode = $this->fetchMode; |
202 | - $ret = $this->_driver->SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); |
|
202 | + $ret = $this->_driver->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache); |
|
203 | 203 | $this->_driver->fetchMode = $save; |
204 | 204 | return $ret; |
205 | 205 | } |
@@ -210,20 +210,20 @@ discard block |
||
210 | 210 | return $this->_driver->ServerInfo(); |
211 | 211 | } |
212 | 212 | |
213 | - function MetaTables($ttype=false,$showSchema=false,$mask=false) |
|
213 | + function MetaTables($ttype = false, $showSchema = false, $mask = false) |
|
214 | 214 | { |
215 | - return $this->_driver->MetaTables($ttype,$showSchema,$mask); |
|
215 | + return $this->_driver->MetaTables($ttype, $showSchema, $mask); |
|
216 | 216 | } |
217 | 217 | |
218 | - function MetaColumns($table,$normalize=true) |
|
218 | + function MetaColumns($table, $normalize = true) |
|
219 | 219 | { |
220 | - return $this->_driver->MetaColumns($table,$normalize); |
|
220 | + return $this->_driver->MetaColumns($table, $normalize); |
|
221 | 221 | } |
222 | 222 | |
223 | - function InParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false) |
|
223 | + function InParameter(&$stmt, &$var, $name, $maxLen = 4000, $type = false) |
|
224 | 224 | { |
225 | 225 | $obj = $stmt[1]; |
226 | - if ($type) $obj->bindParam($name,$var,$type,$maxLen); |
|
226 | + if ($type) $obj->bindParam($name, $var, $type, $maxLen); |
|
227 | 227 | else $obj->bindParam($name, $var); |
228 | 228 | } |
229 | 229 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | |
238 | 238 | |
239 | 239 | if ($arr) { |
240 | - if (sizeof($arr)<2) return ''; |
|
240 | + if (sizeof($arr) < 2) return ''; |
|
241 | 241 | if ((integer)$arr[1]) return $arr[2]; |
242 | 242 | else return ''; |
243 | 243 | } else return '-1'; |
@@ -265,11 +265,11 @@ discard block |
||
265 | 265 | if ($this->transOff) return true; |
266 | 266 | $this->transCnt += 1; |
267 | 267 | $this->_autocommit = false; |
268 | - $this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT,false); |
|
268 | + $this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT, false); |
|
269 | 269 | return $this->_connectionID->beginTransaction(); |
270 | 270 | } |
271 | 271 | |
272 | - function CommitTrans($ok=true) |
|
272 | + function CommitTrans($ok = true) |
|
273 | 273 | { |
274 | 274 | if (!$this->hasTransactions) return false; |
275 | 275 | if ($this->transOff) return true; |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | $this->_autocommit = true; |
279 | 279 | |
280 | 280 | $ret = $this->_connectionID->commit(); |
281 | - $this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT,true); |
|
281 | + $this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT, true); |
|
282 | 282 | return $ret; |
283 | 283 | } |
284 | 284 | |
@@ -290,14 +290,14 @@ discard block |
||
290 | 290 | $this->_autocommit = true; |
291 | 291 | |
292 | 292 | $ret = $this->_connectionID->rollback(); |
293 | - $this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT,true); |
|
293 | + $this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT, true); |
|
294 | 294 | return $ret; |
295 | 295 | } |
296 | 296 | |
297 | 297 | function Prepare($sql) |
298 | 298 | { |
299 | 299 | $this->_stmt = $this->_connectionID->prepare($sql); |
300 | - if ($this->_stmt) return array($sql,$this->_stmt); |
|
300 | + if ($this->_stmt) return array($sql, $this->_stmt); |
|
301 | 301 | |
302 | 302 | return false; |
303 | 303 | } |
@@ -306,12 +306,12 @@ discard block |
||
306 | 306 | { |
307 | 307 | $stmt = $this->_connectionID->prepare($sql); |
308 | 308 | if (!$stmt) return false; |
309 | - $obj = new ADOPDOStatement($stmt,$this); |
|
309 | + $obj = new ADOPDOStatement($stmt, $this); |
|
310 | 310 | return $obj; |
311 | 311 | } |
312 | 312 | |
313 | 313 | /* returns queryID or false */ |
314 | - function _query($sql,$inputarr=false) |
|
314 | + function _query($sql, $inputarr = false) |
|
315 | 315 | { |
316 | 316 | if (is_array($sql)) { |
317 | 317 | $stmt = $sql[1]; |
@@ -373,24 +373,24 @@ discard block |
||
373 | 373 | var $_stmt; |
374 | 374 | var $_connectionID; |
375 | 375 | |
376 | - function ADOPDOStatement($stmt,$connection) |
|
376 | + function ADOPDOStatement($stmt, $connection) |
|
377 | 377 | { |
378 | 378 | $this->_stmt = $stmt; |
379 | 379 | $this->_connectionID = $connection; |
380 | 380 | } |
381 | 381 | |
382 | - function Execute($inputArr=false) |
|
382 | + function Execute($inputArr = false) |
|
383 | 383 | { |
384 | 384 | $savestmt = $this->_connectionID->_stmt; |
385 | - $rs = $this->_connectionID->Execute(array(false,$this->_stmt),$inputArr); |
|
385 | + $rs = $this->_connectionID->Execute(array(false, $this->_stmt), $inputArr); |
|
386 | 386 | $this->_connectionID->_stmt = $savestmt; |
387 | 387 | return $rs; |
388 | 388 | } |
389 | 389 | |
390 | - function InParameter(&$var,$name,$maxLen=4000,$type=false) |
|
390 | + function InParameter(&$var, $name, $maxLen = 4000, $type = false) |
|
391 | 391 | { |
392 | 392 | |
393 | - if ($type) $this->_stmt->bindParam($name,$var,$type,$maxLen); |
|
393 | + if ($type) $this->_stmt->bindParam($name, $var, $type, $maxLen); |
|
394 | 394 | else $this->_stmt->bindParam($name, $var); |
395 | 395 | } |
396 | 396 | |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | else $arr = $this->_connectionID->errorInfo(); |
406 | 406 | |
407 | 407 | if (is_array($arr)) { |
408 | - if ((integer) $arr[0] && isset($arr[2])) return $arr[2]; |
|
408 | + if ((integer)$arr[0] && isset($arr[2])) return $arr[2]; |
|
409 | 409 | else return ''; |
410 | 410 | } else return '-1'; |
411 | 411 | } |
@@ -432,14 +432,14 @@ discard block |
||
432 | 432 | var $databaseType = "pdo"; |
433 | 433 | var $dataProvider = "pdo"; |
434 | 434 | |
435 | - function ADORecordSet_pdo($id,$mode=false) |
|
435 | + function ADORecordSet_pdo($id, $mode = false) |
|
436 | 436 | { |
437 | 437 | if ($mode === false) { |
438 | 438 | global $ADODB_FETCH_MODE; |
439 | 439 | $mode = $ADODB_FETCH_MODE; |
440 | 440 | } |
441 | 441 | $this->adodbFetchMode = $mode; |
442 | - switch($mode) { |
|
442 | + switch ($mode) { |
|
443 | 443 | case ADODB_FETCH_NUM: $mode = PDO_FETCH_NUM; break; |
444 | 444 | case ADODB_FETCH_ASSOC: $mode = PDO_FETCH_ASSOC; break; |
445 | 445 | |
@@ -484,9 +484,9 @@ discard block |
||
484 | 484 | // returns the field object |
485 | 485 | function &FetchField($fieldOffset = -1) |
486 | 486 | { |
487 | - $off=$fieldOffset+1; // offsets begin at 1 |
|
487 | + $off = $fieldOffset + 1; // offsets begin at 1 |
|
488 | 488 | |
489 | - $o= new ADOFieldObject(); |
|
489 | + $o = new ADOFieldObject(); |
|
490 | 490 | $arr = @$this->_queryID->getColumnMeta($fieldOffset); |
491 | 491 | if (!$arr) { |
492 | 492 | $o->name = 'bad getColumnMeta()'; |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | |
533 | 533 | if (!$this->bind) { |
534 | 534 | $this->bind = array(); |
535 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
535 | + for ($i = 0; $i < $this->_numOfFields; $i++) { |
|
536 | 536 | $o = $this->FetchField($i); |
537 | 537 | $this->bind[strtoupper($o->name)] = $i; |
538 | 538 | } |
@@ -15,7 +15,10 @@ discard block |
||
15 | 15 | LOB handling for CLOB/BLOB differs significantly |
16 | 16 | */ |
17 | 17 | // security - hide paths |
18 | -if (!defined('ADODB_DIR')) die(); |
|
18 | +if (!defined('ADODB_DIR')) |
|
19 | +{ |
|
20 | + die(); |
|
21 | +} |
|
19 | 22 | |
20 | 23 | |
21 | 24 | /* |
@@ -50,7 +53,8 @@ discard block |
||
50 | 53 | |
51 | 54 | function adodb_pdo_type($t) |
52 | 55 | { |
53 | - switch($t) { |
|
56 | + switch($t) |
|
57 | + { |
|
54 | 58 | case 2: return 'VARCHAR'; |
55 | 59 | case 3: return 'BLOB'; |
56 | 60 | default: return 'NUMERIC'; |
@@ -64,7 +68,8 @@ discard block |
||
64 | 68 | |
65 | 69 | |
66 | 70 | |
67 | -class ADODB_pdo_base extends ADODB_pdo { |
|
71 | +class ADODB_pdo_base extends ADODB_pdo |
|
72 | +{ |
|
68 | 73 | |
69 | 74 | function _init($parentDriver) |
70 | 75 | { |
@@ -95,7 +100,8 @@ discard block |
||
95 | 100 | } |
96 | 101 | |
97 | 102 | |
98 | -class ADODB_pdo extends ADOConnection { |
|
103 | +class ADODB_pdo extends ADOConnection |
|
104 | +{ |
|
99 | 105 | var $databaseType = "pdo"; |
100 | 106 | var $dataProvider = "pdo"; |
101 | 107 | var $fmtDate = "'Y-m-d'"; |
@@ -145,7 +151,8 @@ discard block |
||
145 | 151 | |
146 | 152 | try { |
147 | 153 | $this->_connectionID = new PDO($argDSN, $argUsername, $argPassword); |
148 | - } catch (Exception $e) { |
|
154 | + } |
|
155 | + catch (Exception $e) { |
|
149 | 156 | $this->_connectionID = false; |
150 | 157 | $this->_errorno = -1; |
151 | 158 | //var_dump($e); |
@@ -153,8 +160,10 @@ discard block |
||
153 | 160 | return false; |
154 | 161 | } |
155 | 162 | |
156 | - if ($this->_connectionID) { |
|
157 | - switch(ADODB_ASSOC_CASE){ |
|
163 | + if ($this->_connectionID) |
|
164 | + { |
|
165 | + switch(ADODB_ASSOC_CASE) |
|
166 | + { |
|
158 | 167 | case 0: $m = PDO_CASE_LOWER; break; |
159 | 168 | case 1: $m = PDO_CASE_UPPER; break; |
160 | 169 | default: |
@@ -166,7 +175,8 @@ discard block |
||
166 | 175 | |
167 | 176 | $class = 'ADODB_pdo_'.$this->dsnType; |
168 | 177 | //$this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT,true); |
169 | - switch($this->dsnType) { |
|
178 | + switch($this->dsnType) |
|
179 | + { |
|
170 | 180 | case 'oci': |
171 | 181 | case 'mysql': |
172 | 182 | case 'pgsql': |
@@ -174,9 +184,12 @@ discard block |
||
174 | 184 | break; |
175 | 185 | } |
176 | 186 | if (class_exists($class)) |
177 | - $this->_driver = new $class(); |
|
178 | - else |
|
179 | - $this->_driver = new ADODB_pdo_base(); |
|
187 | + { |
|
188 | + $this->_driver = new $class(); |
|
189 | + } |
|
190 | + else { |
|
191 | + $this->_driver = new ADODB_pdo_base(); |
|
192 | + } |
|
180 | 193 | |
181 | 194 | $this->_driver->_connectionID = $this->_connectionID; |
182 | 195 | $this->_UpdatePDO(); |
@@ -223,58 +236,122 @@ discard block |
||
223 | 236 | function InParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false) |
224 | 237 | { |
225 | 238 | $obj = $stmt[1]; |
226 | - if ($type) $obj->bindParam($name,$var,$type,$maxLen); |
|
227 | - else $obj->bindParam($name, $var); |
|
239 | + if ($type) |
|
240 | + { |
|
241 | + $obj->bindParam($name,$var,$type,$maxLen); |
|
242 | + } |
|
243 | + else { |
|
244 | + $obj->bindParam($name, $var); |
|
245 | + } |
|
228 | 246 | } |
229 | 247 | |
230 | 248 | |
231 | 249 | function ErrorMsg() |
232 | 250 | { |
233 | - if ($this->_errormsg !== false) return $this->_errormsg; |
|
234 | - if (!empty($this->_stmt)) $arr = $this->_stmt->errorInfo(); |
|
235 | - else if (!empty($this->_connectionID)) $arr = $this->_connectionID->errorInfo(); |
|
236 | - else return 'No Connection Established'; |
|
251 | + if ($this->_errormsg !== false) |
|
252 | + { |
|
253 | + return $this->_errormsg; |
|
254 | + } |
|
255 | + if (!empty($this->_stmt)) |
|
256 | + { |
|
257 | + $arr = $this->_stmt->errorInfo(); |
|
258 | + } |
|
259 | + else if (!empty($this->_connectionID)) |
|
260 | + { |
|
261 | + $arr = $this->_connectionID->errorInfo(); |
|
262 | + } |
|
263 | + else { |
|
264 | + return 'No Connection Established'; |
|
265 | + } |
|
237 | 266 | |
238 | 267 | |
239 | - if ($arr) { |
|
240 | - if (sizeof($arr)<2) return ''; |
|
241 | - if ((integer)$arr[1]) return $arr[2]; |
|
242 | - else return ''; |
|
243 | - } else return '-1'; |
|
268 | + if ($arr) |
|
269 | + { |
|
270 | + if (sizeof($arr)<2) |
|
271 | + { |
|
272 | + return ''; |
|
273 | + } |
|
274 | + if ((integer)$arr[1]) |
|
275 | + { |
|
276 | + return $arr[2]; |
|
277 | + } |
|
278 | + else { |
|
279 | + return ''; |
|
280 | + } |
|
281 | + } |
|
282 | + else { |
|
283 | + return '-1'; |
|
284 | + } |
|
244 | 285 | } |
245 | 286 | |
246 | 287 | |
247 | 288 | function ErrorNo() |
248 | 289 | { |
249 | - if ($this->_errorno !== false) return $this->_errorno; |
|
250 | - if (!empty($this->_stmt)) $err = $this->_stmt->errorCode(); |
|
251 | - else if (!empty($this->_connectionID)) { |
|
290 | + if ($this->_errorno !== false) |
|
291 | + { |
|
292 | + return $this->_errorno; |
|
293 | + } |
|
294 | + if (!empty($this->_stmt)) |
|
295 | + { |
|
296 | + $err = $this->_stmt->errorCode(); |
|
297 | + } |
|
298 | + else if (!empty($this->_connectionID)) |
|
299 | + { |
|
252 | 300 | $arr = $this->_connectionID->errorInfo(); |
253 | - if (isset($arr[0])) $err = $arr[0]; |
|
254 | - else $err = -1; |
|
255 | - } else |
|
256 | - return 0; |
|
301 | + if (isset($arr[0])) |
|
302 | + { |
|
303 | + $err = $arr[0]; |
|
304 | + } |
|
305 | + else { |
|
306 | + $err = -1; |
|
307 | + } |
|
308 | + } |
|
309 | + else { |
|
310 | + return 0; |
|
311 | + } |
|
257 | 312 | |
258 | - if ($err == '00000') return 0; // allows empty check |
|
313 | + if ($err == '00000') |
|
314 | + { |
|
315 | + return 0; |
|
316 | + } |
|
317 | + // allows empty check |
|
259 | 318 | return $err; |
260 | 319 | } |
261 | 320 | |
262 | 321 | function BeginTrans() |
263 | - { |
|
264 | - if (!$this->hasTransactions) return false; |
|
265 | - if ($this->transOff) return true; |
|
322 | + { |
|
323 | + if (!$this->hasTransactions) |
|
324 | + { |
|
325 | + return false; |
|
326 | + } |
|
327 | + if ($this->transOff) |
|
328 | + { |
|
329 | + return true; |
|
330 | + } |
|
266 | 331 | $this->transCnt += 1; |
267 | 332 | $this->_autocommit = false; |
268 | 333 | $this->_connectionID->setAttribute(PDO_ATTR_AUTOCOMMIT,false); |
269 | 334 | return $this->_connectionID->beginTransaction(); |
270 | 335 | } |
271 | 336 | |
272 | - function CommitTrans($ok=true) |
|
273 | - { |
|
274 | - if (!$this->hasTransactions) return false; |
|
275 | - if ($this->transOff) return true; |
|
276 | - if (!$ok) return $this->RollbackTrans(); |
|
277 | - if ($this->transCnt) $this->transCnt -= 1; |
|
337 | + function CommitTrans($ok=true) |
|
338 | + { |
|
339 | + if (!$this->hasTransactions) |
|
340 | + { |
|
341 | + return false; |
|
342 | + } |
|
343 | + if ($this->transOff) |
|
344 | + { |
|
345 | + return true; |
|
346 | + } |
|
347 | + if (!$ok) |
|
348 | + { |
|
349 | + return $this->RollbackTrans(); |
|
350 | + } |
|
351 | + if ($this->transCnt) |
|
352 | + { |
|
353 | + $this->transCnt -= 1; |
|
354 | + } |
|
278 | 355 | $this->_autocommit = true; |
279 | 356 | |
280 | 357 | $ret = $this->_connectionID->commit(); |
@@ -284,9 +361,18 @@ discard block |
||
284 | 361 | |
285 | 362 | function RollbackTrans() |
286 | 363 | { |
287 | - if (!$this->hasTransactions) return false; |
|
288 | - if ($this->transOff) return true; |
|
289 | - if ($this->transCnt) $this->transCnt -= 1; |
|
364 | + if (!$this->hasTransactions) |
|
365 | + { |
|
366 | + return false; |
|
367 | + } |
|
368 | + if ($this->transOff) |
|
369 | + { |
|
370 | + return true; |
|
371 | + } |
|
372 | + if ($this->transCnt) |
|
373 | + { |
|
374 | + $this->transCnt -= 1; |
|
375 | + } |
|
290 | 376 | $this->_autocommit = true; |
291 | 377 | |
292 | 378 | $ret = $this->_connectionID->rollback(); |
@@ -297,7 +383,10 @@ discard block |
||
297 | 383 | function Prepare($sql) |
298 | 384 | { |
299 | 385 | $this->_stmt = $this->_connectionID->prepare($sql); |
300 | - if ($this->_stmt) return array($sql,$this->_stmt); |
|
386 | + if ($this->_stmt) |
|
387 | + { |
|
388 | + return array($sql,$this->_stmt); |
|
389 | + } |
|
301 | 390 | |
302 | 391 | return false; |
303 | 392 | } |
@@ -305,43 +394,60 @@ discard block |
||
305 | 394 | function PrepareStmt($sql) |
306 | 395 | { |
307 | 396 | $stmt = $this->_connectionID->prepare($sql); |
308 | - if (!$stmt) return false; |
|
397 | + if (!$stmt) |
|
398 | + { |
|
399 | + return false; |
|
400 | + } |
|
309 | 401 | $obj = new ADOPDOStatement($stmt,$this); |
310 | 402 | return $obj; |
311 | 403 | } |
312 | 404 | |
313 | 405 | /* returns queryID or false */ |
314 | - function _query($sql,$inputarr=false) |
|
406 | + function _query($sql,$inputarr=false) |
|
315 | 407 | { |
316 | - if (is_array($sql)) { |
|
408 | + if (is_array($sql)) |
|
409 | + { |
|
317 | 410 | $stmt = $sql[1]; |
318 | - } else { |
|
411 | + } |
|
412 | + else |
|
413 | + { |
|
319 | 414 | $stmt = $this->_connectionID->prepare($sql); |
320 | 415 | } |
321 | 416 | |
322 | - if ($stmt) { |
|
323 | - if ($inputarr) $ok = $stmt->execute($inputarr); |
|
324 | - else $ok = $stmt->execute(); |
|
417 | + if ($stmt) |
|
418 | + { |
|
419 | + if ($inputarr) |
|
420 | + { |
|
421 | + $ok = $stmt->execute($inputarr); |
|
422 | + } |
|
423 | + else { |
|
424 | + $ok = $stmt->execute(); |
|
425 | + } |
|
325 | 426 | } |
326 | 427 | |
327 | 428 | |
328 | 429 | $this->_errormsg = false; |
329 | 430 | $this->_errorno = false; |
330 | 431 | |
331 | - if ($ok) { |
|
432 | + if ($ok) |
|
433 | + { |
|
332 | 434 | $this->_stmt = $stmt; |
333 | 435 | return $stmt; |
334 | 436 | } |
335 | 437 | |
336 | - if ($stmt) { |
|
438 | + if ($stmt) |
|
439 | + { |
|
337 | 440 | |
338 | 441 | $arr = $stmt->errorinfo(); |
339 | - if ((integer)$arr[1]) { |
|
442 | + if ((integer)$arr[1]) |
|
443 | + { |
|
340 | 444 | $this->_errormsg = $arr[2]; |
341 | 445 | $this->_errorno = $arr[1]; |
342 | 446 | } |
343 | 447 | |
344 | - } else { |
|
448 | + } |
|
449 | + else |
|
450 | + { |
|
345 | 451 | $this->_errormsg = false; |
346 | 452 | $this->_errorno = false; |
347 | 453 | } |
@@ -366,7 +472,8 @@ discard block |
||
366 | 472 | } |
367 | 473 | } |
368 | 474 | |
369 | -class ADOPDOStatement { |
|
475 | +class ADOPDOStatement |
|
476 | +{ |
|
370 | 477 | |
371 | 478 | var $databaseType = "pdo"; |
372 | 479 | var $dataProvider = "pdo"; |
@@ -390,8 +497,13 @@ discard block |
||
390 | 497 | function InParameter(&$var,$name,$maxLen=4000,$type=false) |
391 | 498 | { |
392 | 499 | |
393 | - if ($type) $this->_stmt->bindParam($name,$var,$type,$maxLen); |
|
394 | - else $this->_stmt->bindParam($name, $var); |
|
500 | + if ($type) |
|
501 | + { |
|
502 | + $this->_stmt->bindParam($name,$var,$type,$maxLen); |
|
503 | + } |
|
504 | + else { |
|
505 | + $this->_stmt->bindParam($name, $var); |
|
506 | + } |
|
395 | 507 | } |
396 | 508 | |
397 | 509 | function Affected_Rows() |
@@ -401,13 +513,27 @@ discard block |
||
401 | 513 | |
402 | 514 | function ErrorMsg() |
403 | 515 | { |
404 | - if ($this->_stmt) $arr = $this->_stmt->errorInfo(); |
|
405 | - else $arr = $this->_connectionID->errorInfo(); |
|
516 | + if ($this->_stmt) |
|
517 | + { |
|
518 | + $arr = $this->_stmt->errorInfo(); |
|
519 | + } |
|
520 | + else { |
|
521 | + $arr = $this->_connectionID->errorInfo(); |
|
522 | + } |
|
406 | 523 | |
407 | - if (is_array($arr)) { |
|
408 | - if ((integer) $arr[0] && isset($arr[2])) return $arr[2]; |
|
409 | - else return ''; |
|
410 | - } else return '-1'; |
|
524 | + if (is_array($arr)) |
|
525 | + { |
|
526 | + if ((integer) $arr[0] && isset($arr[2])) |
|
527 | + { |
|
528 | + return $arr[2]; |
|
529 | + } |
|
530 | + else { |
|
531 | + return ''; |
|
532 | + } |
|
533 | + } |
|
534 | + else { |
|
535 | + return '-1'; |
|
536 | + } |
|
411 | 537 | } |
412 | 538 | |
413 | 539 | function NumCols() |
@@ -417,8 +543,13 @@ discard block |
||
417 | 543 | |
418 | 544 | function ErrorNo() |
419 | 545 | { |
420 | - if ($this->_stmt) return $this->_stmt->errorCode(); |
|
421 | - else return $this->_connectionID->errorInfo(); |
|
546 | + if ($this->_stmt) |
|
547 | + { |
|
548 | + return $this->_stmt->errorCode(); |
|
549 | + } |
|
550 | + else { |
|
551 | + return $this->_connectionID->errorInfo(); |
|
552 | + } |
|
422 | 553 | } |
423 | 554 | } |
424 | 555 | |
@@ -426,7 +557,8 @@ discard block |
||
426 | 557 | Class Name: Recordset |
427 | 558 | --------------------------------------------------------------------------------------*/ |
428 | 559 | |
429 | -class ADORecordSet_pdo extends ADORecordSet { |
|
560 | +class ADORecordSet_pdo extends ADORecordSet |
|
561 | +{ |
|
430 | 562 | |
431 | 563 | var $bind = false; |
432 | 564 | var $databaseType = "pdo"; |
@@ -434,12 +566,14 @@ discard block |
||
434 | 566 | |
435 | 567 | function ADORecordSet_pdo($id,$mode=false) |
436 | 568 | { |
437 | - if ($mode === false) { |
|
569 | + if ($mode === false) |
|
570 | + { |
|
438 | 571 | global $ADODB_FETCH_MODE; |
439 | 572 | $mode = $ADODB_FETCH_MODE; |
440 | 573 | } |
441 | 574 | $this->adodbFetchMode = $mode; |
442 | - switch($mode) { |
|
575 | + switch($mode) |
|
576 | + { |
|
443 | 577 | case ADODB_FETCH_NUM: $mode = PDO_FETCH_NUM; break; |
444 | 578 | case ADODB_FETCH_ASSOC: $mode = PDO_FETCH_ASSOC; break; |
445 | 579 | |
@@ -455,19 +589,30 @@ discard block |
||
455 | 589 | |
456 | 590 | function Init() |
457 | 591 | { |
458 | - if ($this->_inited) return; |
|
592 | + if ($this->_inited) |
|
593 | + { |
|
594 | + return; |
|
595 | + } |
|
459 | 596 | $this->_inited = true; |
460 | - if ($this->_queryID) @$this->_initrs(); |
|
461 | - else { |
|
597 | + if ($this->_queryID) |
|
598 | + { |
|
599 | + @$this->_initrs(); |
|
600 | + } |
|
601 | + else |
|
602 | + { |
|
462 | 603 | $this->_numOfRows = 0; |
463 | 604 | $this->_numOfFields = 0; |
464 | 605 | } |
465 | - if ($this->_numOfRows != 0 && $this->_currentRow == -1) { |
|
606 | + if ($this->_numOfRows != 0 && $this->_currentRow == -1) |
|
607 | + { |
|
466 | 608 | $this->_currentRow = 0; |
467 | - if ($this->EOF = ($this->_fetch() === false)) { |
|
609 | + if ($this->EOF = ($this->_fetch() === false)) |
|
610 | + { |
|
468 | 611 | $this->_numOfRows = 0; // _numOfRows could be -1 |
469 | 612 | } |
470 | - } else { |
|
613 | + } |
|
614 | + else |
|
615 | + { |
|
471 | 616 | $this->EOF = true; |
472 | 617 | } |
473 | 618 | } |
@@ -477,7 +622,10 @@ discard block |
||
477 | 622 | global $ADODB_COUNTRECS; |
478 | 623 | |
479 | 624 | $this->_numOfRows = ($ADODB_COUNTRECS) ? @$this->_queryID->rowCount() : -1; |
480 | - if (!$this->_numOfRows) $this->_numOfRows = -1; |
|
625 | + if (!$this->_numOfRows) |
|
626 | + { |
|
627 | + $this->_numOfRows = -1; |
|
628 | + } |
|
481 | 629 | $this->_numOfFields = $this->_queryID->columnCount(); |
482 | 630 | } |
483 | 631 | |
@@ -488,7 +636,8 @@ discard block |
||
488 | 636 | |
489 | 637 | $o= new ADOFieldObject(); |
490 | 638 | $arr = @$this->_queryID->getColumnMeta($fieldOffset); |
491 | - if (!$arr) { |
|
639 | + if (!$arr) |
|
640 | + { |
|
492 | 641 | $o->name = 'bad getColumnMeta()'; |
493 | 642 | $o->max_length = -1; |
494 | 643 | $o->type = 'VARCHAR'; |
@@ -498,13 +647,24 @@ discard block |
||
498 | 647 | } |
499 | 648 | //adodb_pr($arr); |
500 | 649 | $o->name = $arr['name']; |
501 | - if (isset($arr['native_type'])) $o->type = $arr['native_type']; |
|
502 | - else $o->type = adodb_pdo_type($arr['pdo_type']); |
|
650 | + if (isset($arr['native_type'])) |
|
651 | + { |
|
652 | + $o->type = $arr['native_type']; |
|
653 | + } |
|
654 | + else { |
|
655 | + $o->type = adodb_pdo_type($arr['pdo_type']); |
|
656 | + } |
|
503 | 657 | $o->max_length = $arr['len']; |
504 | 658 | $o->precision = $arr['precision']; |
505 | 659 | |
506 | - if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name); |
|
507 | - else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name); |
|
660 | + if (ADODB_ASSOC_CASE == 0) |
|
661 | + { |
|
662 | + $o->name = strtolower($o->name); |
|
663 | + } |
|
664 | + else if (ADODB_ASSOC_CASE == 1) |
|
665 | + { |
|
666 | + $o->name = strtoupper($o->name); |
|
667 | + } |
|
508 | 668 | return $o; |
509 | 669 | } |
510 | 670 | |
@@ -515,24 +675,32 @@ discard block |
||
515 | 675 | |
516 | 676 | function _fetch() |
517 | 677 | { |
518 | - if (!$this->_queryID) return false; |
|
678 | + if (!$this->_queryID) |
|
679 | + { |
|
680 | + return false; |
|
681 | + } |
|
519 | 682 | |
520 | 683 | $this->fields = $this->_queryID->fetch($this->fetchMode); |
521 | 684 | return !empty($this->fields); |
522 | 685 | } |
523 | 686 | |
524 | - function _close() |
|
687 | + function _close() |
|
525 | 688 | { |
526 | 689 | $this->_queryID = false; |
527 | 690 | } |
528 | 691 | |
529 | 692 | function Fields($colname) |
530 | 693 | { |
531 | - if ($this->adodbFetchMode != ADODB_FETCH_NUM) return @$this->fields[$colname]; |
|
694 | + if ($this->adodbFetchMode != ADODB_FETCH_NUM) |
|
695 | + { |
|
696 | + return @$this->fields[$colname]; |
|
697 | + } |
|
532 | 698 | |
533 | - if (!$this->bind) { |
|
699 | + if (!$this->bind) |
|
700 | + { |
|
534 | 701 | $this->bind = array(); |
535 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
702 | + for ($i=0; $i < $this->_numOfFields; $i++) |
|
703 | + { |
|
536 | 704 | $o = $this->FetchField($i); |
537 | 705 | $this->bind[strtoupper($o->name)] = $i; |
538 | 706 | } |
@@ -702,6 +702,10 @@ discard block |
||
702 | 702 | |
703 | 703 | |
704 | 704 | // returns queryID or false |
705 | + |
|
706 | + /** |
|
707 | + * @param boolean $inputarr |
|
708 | + */ |
|
705 | 709 | function _query($sql,$inputarr) |
706 | 710 | { |
707 | 711 | |
@@ -782,6 +786,10 @@ discard block |
||
782 | 786 | |
783 | 787 | |
784 | 788 | /* Returns: the last error message from previous database operation */ |
789 | + |
|
790 | + /** |
|
791 | + * @return boolean|string |
|
792 | + */ |
|
785 | 793 | function ErrorMsg() |
786 | 794 | { |
787 | 795 | if ($this->_errorMsg !== false) return $this->_errorMsg; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | var $_resultid = false; |
62 | 62 | var $concat_operator='||'; |
63 | 63 | var $metaDatabasesSQL = "select datname from pg_database where datname not in ('template0','template1') order by 1"; |
64 | - var $metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' |
|
64 | + var $metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' |
|
65 | 65 | and tablename not in ('sql_features', 'sql_implementation_info', 'sql_languages', |
66 | 66 | 'sql_packages', 'sql_sizing', 'sql_sizing_profiles') |
67 | 67 | union |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | { |
227 | 227 | $info = $this->ServerInfo(); |
228 | 228 | if ($info['version'] >= 7.3) { |
229 | - $this->metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' |
|
229 | + $this->metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' |
|
230 | 230 | and schemaname not in ( 'pg_catalog','information_schema') |
231 | 231 | union |
232 | 232 | select viewname,'V' from pg_views where viewname not like 'pg\_%' and schemaname not in ( 'pg_catalog','information_schema') "; |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | { |
444 | 444 | |
445 | 445 | if ($blobtype == 'CLOB') { |
446 | - return $this->Execute("UPDATE $table SET $column=" . $this->qstr($val) . " WHERE $where"); |
|
446 | + return $this->Execute("UPDATE $table SET $column=" . $this->qstr($val) . " WHERE $where"); |
|
447 | 447 | } |
448 | 448 | // do not use bind params which uses qstr(), as blobencode() already quotes data |
449 | 449 | return $this->Execute("UPDATE $table SET $column='".$this->BlobEncode($val)."'::bytea WHERE $where"); |
@@ -573,8 +573,8 @@ discard block |
||
573 | 573 | } |
574 | 574 | |
575 | 575 | function &MetaIndexes ($table, $primary = FALSE) |
576 | - { |
|
577 | - global $ADODB_FETCH_MODE; |
|
576 | + { |
|
577 | + global $ADODB_FETCH_MODE; |
|
578 | 578 | |
579 | 579 | // table-name must NOT be quoted, otherwise we will not find any index |
580 | 580 | $table = str_replace($this->nameQuote, '', $table); |
@@ -591,50 +591,50 @@ discard block |
||
591 | 591 | ,pg_namespace n |
592 | 592 | WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\')) and c.relnamespace=c2.relnamespace and c.relnamespace=n.oid and n.nspname=\'%s\' AND i.indisprimary=false'; |
593 | 593 | } else { |
594 | - $sql = ' |
|
594 | + $sql = ' |
|
595 | 595 | SELECT c.relname as "Name", i.indisunique as "Unique", i.indkey as "Columns" |
596 | 596 | FROM pg_catalog.pg_class c |
597 | 597 | JOIN pg_catalog.pg_index i ON i.indexrelid=c.oid |
598 | 598 | JOIN pg_catalog.pg_class c2 ON c2.oid=i.indrelid |
599 | 599 | WHERE c2.relname=\'%s\' or c2.relname=lower(\'%s\')'; |
600 | - } |
|
601 | - |
|
602 | - if ($primary == FALSE) { |
|
603 | - $sql .= ' AND i.indisprimary=false;'; |
|
604 | - } |
|
605 | - |
|
606 | - $save = $ADODB_FETCH_MODE; |
|
607 | - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|
608 | - if ($this->fetchMode !== FALSE) { |
|
609 | - $savem = $this->SetFetchMode(FALSE); |
|
610 | - } |
|
611 | - |
|
612 | - $rs = $this->Execute(sprintf($sql,$table,$table,$schema)); |
|
613 | - if (isset($savem)) { |
|
614 | - $this->SetFetchMode($savem); |
|
615 | - } |
|
616 | - $ADODB_FETCH_MODE = $save; |
|
617 | - |
|
618 | - if (!is_object($rs)) { |
|
619 | - $false = false; |
|
600 | + } |
|
601 | + |
|
602 | + if ($primary == FALSE) { |
|
603 | + $sql .= ' AND i.indisprimary=false;'; |
|
604 | + } |
|
605 | + |
|
606 | + $save = $ADODB_FETCH_MODE; |
|
607 | + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|
608 | + if ($this->fetchMode !== FALSE) { |
|
609 | + $savem = $this->SetFetchMode(FALSE); |
|
610 | + } |
|
611 | + |
|
612 | + $rs = $this->Execute(sprintf($sql,$table,$table,$schema)); |
|
613 | + if (isset($savem)) { |
|
614 | + $this->SetFetchMode($savem); |
|
615 | + } |
|
616 | + $ADODB_FETCH_MODE = $save; |
|
617 | + |
|
618 | + if (!is_object($rs)) { |
|
619 | + $false = false; |
|
620 | 620 | return $false; |
621 | - } |
|
622 | - |
|
623 | - $col_names = $this->MetaColumnNames($table,true); |
|
624 | - $indexes = array(); |
|
625 | - while ($row = $rs->FetchRow()) { |
|
626 | - $columns = array(); |
|
627 | - foreach (explode(' ', $row[2]) as $col) { |
|
628 | - $columns[] = $col_names[$col - 1]; |
|
629 | - } |
|
630 | - |
|
631 | - $indexes[$row[0]] = array( |
|
632 | - 'unique' => ($row[1] == 't'), |
|
633 | - 'columns' => $columns |
|
634 | - ); |
|
635 | - } |
|
636 | - return $indexes; |
|
637 | - } |
|
621 | + } |
|
622 | + |
|
623 | + $col_names = $this->MetaColumnNames($table,true); |
|
624 | + $indexes = array(); |
|
625 | + while ($row = $rs->FetchRow()) { |
|
626 | + $columns = array(); |
|
627 | + foreach (explode(' ', $row[2]) as $col) { |
|
628 | + $columns[] = $col_names[$col - 1]; |
|
629 | + } |
|
630 | + |
|
631 | + $indexes[$row[0]] = array( |
|
632 | + 'unique' => ($row[1] == 't'), |
|
633 | + 'columns' => $columns |
|
634 | + ); |
|
635 | + } |
|
636 | + return $indexes; |
|
637 | + } |
|
638 | 638 | |
639 | 639 | // returns true or false |
640 | 640 | // |
@@ -967,7 +967,7 @@ discard block |
||
967 | 967 | { |
968 | 968 | |
969 | 969 | if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0) |
970 | - return false; |
|
970 | + return false; |
|
971 | 971 | |
972 | 972 | $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); |
973 | 973 |
@@ -287,64 +287,64 @@ discard block |
||
287 | 287 | for ($i=0; $i < $len; $i++) { |
288 | 288 | $ch = $fmt[$i]; |
289 | 289 | switch($ch) { |
290 | - case 'Y': |
|
291 | - case 'y': |
|
292 | - $s .= 'YYYY'; |
|
293 | - break; |
|
294 | - case 'Q': |
|
295 | - case 'q': |
|
296 | - $s .= 'Q'; |
|
297 | - break; |
|
298 | - |
|
299 | - case 'M': |
|
300 | - $s .= 'Mon'; |
|
301 | - break; |
|
302 | - |
|
303 | - case 'm': |
|
304 | - $s .= 'MM'; |
|
305 | - break; |
|
306 | - case 'D': |
|
307 | - case 'd': |
|
308 | - $s .= 'DD'; |
|
309 | - break; |
|
310 | - |
|
311 | - case 'H': |
|
312 | - $s.= 'HH24'; |
|
313 | - break; |
|
314 | - |
|
315 | - case 'h': |
|
316 | - $s .= 'HH'; |
|
317 | - break; |
|
318 | - |
|
319 | - case 'i': |
|
320 | - $s .= 'MI'; |
|
321 | - break; |
|
322 | - |
|
323 | - case 's': |
|
324 | - $s .= 'SS'; |
|
325 | - break; |
|
326 | - |
|
327 | - case 'a': |
|
328 | - case 'A': |
|
329 | - $s .= 'AM'; |
|
330 | - break; |
|
331 | - |
|
332 | - case 'w': |
|
333 | - $s .= 'D'; |
|
334 | - break; |
|
335 | - |
|
336 | - case 'l': |
|
337 | - $s .= 'DAY'; |
|
338 | - break; |
|
339 | - |
|
340 | - default: |
|
341 | - // handle escape characters... |
|
342 | - if ($ch == '\\') { |
|
343 | - $i++; |
|
344 | - $ch = substr($fmt,$i,1); |
|
345 | - } |
|
346 | - if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; |
|
347 | - else $s .= '"'.$ch.'"'; |
|
290 | + case 'Y': |
|
291 | + case 'y': |
|
292 | + $s .= 'YYYY'; |
|
293 | + break; |
|
294 | + case 'Q': |
|
295 | + case 'q': |
|
296 | + $s .= 'Q'; |
|
297 | + break; |
|
298 | + |
|
299 | + case 'M': |
|
300 | + $s .= 'Mon'; |
|
301 | + break; |
|
302 | + |
|
303 | + case 'm': |
|
304 | + $s .= 'MM'; |
|
305 | + break; |
|
306 | + case 'D': |
|
307 | + case 'd': |
|
308 | + $s .= 'DD'; |
|
309 | + break; |
|
310 | + |
|
311 | + case 'H': |
|
312 | + $s.= 'HH24'; |
|
313 | + break; |
|
314 | + |
|
315 | + case 'h': |
|
316 | + $s .= 'HH'; |
|
317 | + break; |
|
318 | + |
|
319 | + case 'i': |
|
320 | + $s .= 'MI'; |
|
321 | + break; |
|
322 | + |
|
323 | + case 's': |
|
324 | + $s .= 'SS'; |
|
325 | + break; |
|
326 | + |
|
327 | + case 'a': |
|
328 | + case 'A': |
|
329 | + $s .= 'AM'; |
|
330 | + break; |
|
331 | + |
|
332 | + case 'w': |
|
333 | + $s .= 'D'; |
|
334 | + break; |
|
335 | + |
|
336 | + case 'l': |
|
337 | + $s .= 'DAY'; |
|
338 | + break; |
|
339 | + |
|
340 | + default: |
|
341 | + // handle escape characters... |
|
342 | + if ($ch == '\\') { |
|
343 | + $i++; |
|
344 | + $ch = substr($fmt,$i,1); |
|
345 | + } |
|
346 | + if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; |
|
347 | + else $s .= '"'.$ch.'"'; |
|
348 | 348 | |
349 | 349 | } |
350 | 350 | } |
@@ -859,12 +859,12 @@ discard block |
||
859 | 859 | } |
860 | 860 | switch ($mode) |
861 | 861 | { |
862 | - case ADODB_FETCH_NUM: $this->fetchMode = PGSQL_NUM; break; |
|
863 | - case ADODB_FETCH_ASSOC:$this->fetchMode = PGSQL_ASSOC; break; |
|
862 | + case ADODB_FETCH_NUM: $this->fetchMode = PGSQL_NUM; break; |
|
863 | + case ADODB_FETCH_ASSOC:$this->fetchMode = PGSQL_ASSOC; break; |
|
864 | 864 | |
865 | - case ADODB_FETCH_DEFAULT: |
|
866 | - case ADODB_FETCH_BOTH: |
|
867 | - default: $this->fetchMode = PGSQL_BOTH; break; |
|
865 | + case ADODB_FETCH_DEFAULT: |
|
866 | + case ADODB_FETCH_BOTH: |
|
867 | + default: $this->fetchMode = PGSQL_BOTH; break; |
|
868 | 868 | } |
869 | 869 | $this->adodbFetchMode = $mode; |
870 | 870 | $this->ADORecordSet($queryID); |
@@ -49,17 +49,17 @@ discard block |
||
49 | 49 | { |
50 | 50 | $len = strlen($s); |
51 | 51 | if ($len == 0) return "''"; |
52 | - if (strncmp($s,"'",1) === 0 && substr(s,$len-1) == "'") return $s; // already quoted |
|
52 | + if (strncmp($s, "'", 1) === 0 && substr(s, $len - 1) == "'") return $s; // already quoted |
|
53 | 53 | |
54 | 54 | return "'".addslashes($s)."'"; |
55 | 55 | } |
56 | 56 | |
57 | -class ADODB_postgres64 extends ADOConnection{ |
|
57 | +class ADODB_postgres64 extends ADOConnection { |
|
58 | 58 | var $databaseType = 'postgres64'; |
59 | 59 | var $dataProvider = 'postgres'; |
60 | 60 | var $hasInsertID = true; |
61 | 61 | var $_resultid = false; |
62 | - var $concat_operator='||'; |
|
62 | + var $concat_operator = '||'; |
|
63 | 63 | var $metaDatabasesSQL = "select datname from pg_database where datname not in ('template0','template1') order by 1"; |
64 | 64 | var $metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' |
65 | 65 | and tablename not in ('sql_features', 'sql_implementation_info', 'sql_languages', |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a WHERE bc.oid = i.indrelid AND ic.oid = i.indexrelid AND (i.indkey[0] = a.attnum OR i.indkey[1] = a.attnum OR i.indkey[2] = a.attnum OR i.indkey[3] = a.attnum OR i.indkey[4] = a.attnum OR i.indkey[5] = a.attnum OR i.indkey[6] = a.attnum OR i.indkey[7] = a.attnum) AND a.attrelid = bc.oid AND bc.relname = '%s'"; |
90 | 90 | |
91 | 91 | var $hasAffectedRows = true; |
92 | - var $hasLimit = false; // set to true for pgsql 7 only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10 |
|
92 | + var $hasLimit = false; // set to true for pgsql 7 only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10 |
|
93 | 93 | // below suggested by Freek Dijkstra |
94 | - var $true = 'TRUE'; // string that represents TRUE for a database |
|
95 | - var $false = 'FALSE'; // string that represents FALSE for a database |
|
96 | - var $fmtDate = "'Y-m-d'"; // used by DBDate() as the default date format used by the database |
|
94 | + var $true = 'TRUE'; // string that represents TRUE for a database |
|
95 | + var $false = 'FALSE'; // string that represents FALSE for a database |
|
96 | + var $fmtDate = "'Y-m-d'"; // used by DBDate() as the default date format used by the database |
|
97 | 97 | var $fmtTimeStamp = "'Y-m-d G:i:s'"; // used by DBTimeStamp as the default timestamp fmt. |
98 | 98 | var $hasMoveFirst = true; |
99 | 99 | var $hasGenID = true; |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | var $_genSeqSQL = "CREATE SEQUENCE %s START %s"; |
102 | 102 | var $_dropSeqSQL = "DROP SEQUENCE %s"; |
103 | 103 | var $metaDefaultsSQL = "SELECT d.adnum as num, d.adsrc as def from pg_attrdef d, pg_class c where d.adrelid=c.oid and c.relname='%s' order by d.adnum"; |
104 | - var $random = 'random()'; /// random function |
|
104 | + var $random = 'random()'; /// random function |
|
105 | 105 | var $autoRollback = true; // apparently pgsql does not autorollback properly before php 4.3.4 |
106 | 106 | // http://bugs.php.net/bug.php?id=25404 |
107 | 107 | |
@@ -131,17 +131,17 @@ discard block |
||
131 | 131 | return $arr; |
132 | 132 | } |
133 | 133 | |
134 | - function IfNull( $field, $ifNull ) |
|
134 | + function IfNull($field, $ifNull) |
|
135 | 135 | { |
136 | 136 | return " coalesce($field, $ifNull) "; |
137 | 137 | } |
138 | 138 | |
139 | 139 | // get the last id - never tested |
140 | - function pg_insert_id($tablename,$fieldname) |
|
140 | + function pg_insert_id($tablename, $fieldname) |
|
141 | 141 | { |
142 | - $result=pg_exec($this->_connectionID, "SELECT last_value FROM ${tablename}_${fieldname}_seq"); |
|
142 | + $result = pg_exec($this->_connectionID, "SELECT last_value FROM ${tablename}_${fieldname}_seq"); |
|
143 | 143 | if ($result) { |
144 | - $arr = @pg_fetch_row($result,0); |
|
144 | + $arr = @pg_fetch_row($result, 0); |
|
145 | 145 | pg_freeresult($result); |
146 | 146 | if (isset($arr[0])) return $arr[0]; |
147 | 147 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | Using a OID as a unique identifier is not generally wise. |
153 | 153 | Unless you are very careful, you might end up with a tuple having |
154 | 154 | a different OID if a database must be reloaded. */ |
155 | - function _insertid($table,$column,$try_oid=false) |
|
155 | + function _insertid($table, $column, $try_oid = false) |
|
156 | 156 | { |
157 | 157 | if ($try_oid) |
158 | 158 | { |
@@ -166,13 +166,13 @@ discard block |
||
166 | 166 | if ($oid === false && $table && $column) // table might not use oid's, default for 8.1+ |
167 | 167 | { |
168 | 168 | // try the standard sequence name first, due to table renames etc. this might not be the correct one |
169 | - if (!($ret = $this->GetOne($sql='SELECT currval('.$this->qstr($table.'_'.$column.'_seq').')'))) { |
|
169 | + if (!($ret = $this->GetOne($sql = 'SELECT currval('.$this->qstr($table.'_'.$column.'_seq').')'))) { |
|
170 | 170 | // now we read the sequence name from the database itself, that is a lot slower! |
171 | 171 | $cols = $this->MetaColumns($table); |
172 | 172 | $fld = $cols[strtoupper($column)]; |
173 | 173 | if ($fld->primary_key && $fld->has_default && |
174 | - preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$fld->default_value,$matches)) { |
|
175 | - $ret = $this->GetOne($sql='SELECT currval('.$this->qstr($matches[1]).')'); |
|
174 | + preg_match("/nextval\('([^']+)'::(text|regclass)\)/", $fld->default_value, $matches)) { |
|
175 | + $ret = $this->GetOne($sql = 'SELECT currval('.$this->qstr($matches[1]).')'); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | return $ret; |
@@ -198,14 +198,14 @@ discard block |
||
198 | 198 | return @pg_Exec($this->_connectionID, "begin"); |
199 | 199 | } |
200 | 200 | |
201 | - function RowLock($tables,$where,$flds='1 as ignore') |
|
201 | + function RowLock($tables, $where, $flds = '1 as ignore') |
|
202 | 202 | { |
203 | 203 | if (!$this->transCnt) $this->BeginTrans(); |
204 | 204 | return $this->GetOne("select $flds from $tables where $where for update"); |
205 | 205 | } |
206 | 206 | |
207 | 207 | // returns true/false. |
208 | - function CommitTrans($ok=true) |
|
208 | + function CommitTrans($ok = true) |
|
209 | 209 | { |
210 | 210 | if ($this->transOff) return true; |
211 | 211 | if (!$ok) return $this->RollbackTrans(); |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | return @pg_Exec($this->_connectionID, "rollback"); |
223 | 223 | } |
224 | 224 | |
225 | - function &MetaTables($ttype=false,$showSchema=false,$mask=false) |
|
225 | + function &MetaTables($ttype = false, $showSchema = false, $mask = false) |
|
226 | 226 | { |
227 | 227 | $info = $this->ServerInfo(); |
228 | 228 | if ($info['version'] >= 7.3) { |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | if ($mask) { |
235 | 235 | $save = $this->metaTablesSQL; |
236 | 236 | $mask = $this->qstr(strtolower($mask)); |
237 | - if ($info['version']>=7.3) |
|
237 | + if ($info['version'] >= 7.3) |
|
238 | 238 | $this->metaTablesSQL = " |
239 | 239 | select tablename,'T' from pg_tables where tablename like $mask and schemaname not in ( 'pg_catalog','information_schema') |
240 | 240 | union |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | union |
246 | 246 | select viewname,'V' from pg_views where viewname like $mask"; |
247 | 247 | } |
248 | - $ret =& ADOConnection::MetaTables($ttype,$showSchema); |
|
248 | + $ret = & ADOConnection::MetaTables($ttype, $showSchema); |
|
249 | 249 | |
250 | 250 | if ($mask) { |
251 | 251 | $this->metaTablesSQL = $save; |
@@ -254,39 +254,39 @@ discard block |
||
254 | 254 | } |
255 | 255 | |
256 | 256 | // if magic quotes disabled, use pg_escape_string() |
257 | - function qstr($s,$magic_quotes=false) |
|
257 | + function qstr($s, $magic_quotes = false) |
|
258 | 258 | { |
259 | 259 | if (is_bool($s)) return $s ? 'true' : 'false'; |
260 | 260 | |
261 | 261 | if (!$magic_quotes) { |
262 | 262 | if (ADODB_PHPVER >= 0x5200) { |
263 | - return "'".pg_escape_string($this->_connectionID,$s)."'"; |
|
263 | + return "'".pg_escape_string($this->_connectionID, $s)."'"; |
|
264 | 264 | } |
265 | 265 | if (ADODB_PHPVER >= 0x4200) { |
266 | 266 | return "'".pg_escape_string($s)."'"; |
267 | 267 | } |
268 | - if ($this->replaceQuote[0] == '\\'){ |
|
269 | - $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\\000"),$s); |
|
268 | + if ($this->replaceQuote[0] == '\\') { |
|
269 | + $s = adodb_str_replace(array('\\', "\0"), array('\\\\', "\\\\000"), $s); |
|
270 | 270 | } |
271 | - return "'".str_replace("'",$this->replaceQuote,$s)."'"; |
|
271 | + return "'".str_replace("'", $this->replaceQuote, $s)."'"; |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | // undo magic quotes for " |
275 | - $s = str_replace('\\"','"',$s); |
|
275 | + $s = str_replace('\\"', '"', $s); |
|
276 | 276 | return "'$s'"; |
277 | 277 | } |
278 | 278 | |
279 | 279 | |
280 | 280 | // Format date column in sql string given an input format that understands Y M D |
281 | - function SQLDate($fmt, $col=false) |
|
281 | + function SQLDate($fmt, $col = false) |
|
282 | 282 | { |
283 | 283 | if (!$col) $col = $this->sysTimeStamp; |
284 | 284 | $s = 'TO_CHAR('.$col.",'"; |
285 | 285 | |
286 | 286 | $len = strlen($fmt); |
287 | - for ($i=0; $i < $len; $i++) { |
|
287 | + for ($i = 0; $i < $len; $i++) { |
|
288 | 288 | $ch = $fmt[$i]; |
289 | - switch($ch) { |
|
289 | + switch ($ch) { |
|
290 | 290 | case 'Y': |
291 | 291 | case 'y': |
292 | 292 | $s .= 'YYYY'; |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | break; |
310 | 310 | |
311 | 311 | case 'H': |
312 | - $s.= 'HH24'; |
|
312 | + $s .= 'HH24'; |
|
313 | 313 | break; |
314 | 314 | |
315 | 315 | case 'h': |
@@ -341,14 +341,14 @@ discard block |
||
341 | 341 | // handle escape characters... |
342 | 342 | if ($ch == '\\') { |
343 | 343 | $i++; |
344 | - $ch = substr($fmt,$i,1); |
|
344 | + $ch = substr($fmt, $i, 1); |
|
345 | 345 | } |
346 | - if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; |
|
346 | + if (strpos('-/.:;, ', $ch) !== false) $s .= $ch; |
|
347 | 347 | else $s .= '"'.$ch.'"'; |
348 | 348 | |
349 | 349 | } |
350 | 350 | } |
351 | - return $s. "')"; |
|
351 | + return $s."')"; |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | |
@@ -361,12 +361,12 @@ discard block |
||
361 | 361 | * contributed by Mattia Rossi [email protected] |
362 | 362 | * modified for safe mode by juraj chlebec |
363 | 363 | */ |
364 | - function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') |
|
364 | + function UpdateBlobFile($table, $column, $path, $where, $blobtype = 'BLOB') |
|
365 | 365 | { |
366 | - pg_exec ($this->_connectionID, "begin"); |
|
366 | + pg_exec($this->_connectionID, "begin"); |
|
367 | 367 | |
368 | - $fd = fopen($path,'r'); |
|
369 | - $contents = fread($fd,filesize($path)); |
|
368 | + $fd = fopen($path, 'r'); |
|
369 | + $contents = fread($fd, filesize($path)); |
|
370 | 370 | fclose($fd); |
371 | 371 | |
372 | 372 | $oid = pg_lo_create($this->_connectionID); |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | |
377 | 377 | // $oid = pg_lo_import ($path); |
378 | 378 | pg_exec($this->_connectionID, "commit"); |
379 | - $rs = ADOConnection::UpdateBlob($table,$column,$oid,$where,$blobtype); |
|
379 | + $rs = ADOConnection::UpdateBlob($table, $column, $oid, $where, $blobtype); |
|
380 | 380 | $rez = !empty($rs); |
381 | 381 | return $rez; |
382 | 382 | } |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | */ |
387 | 387 | function GuessOID($oid) |
388 | 388 | { |
389 | - if (strlen($oid)>16) return false; |
|
389 | + if (strlen($oid) > 16) return false; |
|
390 | 390 | return is_numeric($oid); |
391 | 391 | } |
392 | 392 | |
@@ -402,20 +402,20 @@ discard block |
||
402 | 402 | * Since adodb 4.54, this returns the blob, instead of sending it to stdout. Also |
403 | 403 | * added maxsize parameter, which defaults to $db->maxblobsize if not defined. |
404 | 404 | */ |
405 | - function BlobDecode($blob,$maxsize=false,$hastrans=true) |
|
405 | + function BlobDecode($blob, $maxsize = false, $hastrans = true) |
|
406 | 406 | { |
407 | 407 | if (!$this->GuessOID($blob)) return $blob; |
408 | 408 | |
409 | - if ($hastrans) @pg_exec($this->_connectionID,"begin"); |
|
410 | - $fd = @pg_lo_open($this->_connectionID,$blob,"r"); |
|
409 | + if ($hastrans) @pg_exec($this->_connectionID, "begin"); |
|
410 | + $fd = @pg_lo_open($this->_connectionID, $blob, "r"); |
|
411 | 411 | if ($fd === false) { |
412 | - if ($hastrans) @pg_exec($this->_connectionID,"commit"); |
|
412 | + if ($hastrans) @pg_exec($this->_connectionID, "commit"); |
|
413 | 413 | return $blob; |
414 | 414 | } |
415 | 415 | if (!$maxsize) $maxsize = $this->maxblobsize; |
416 | - $realblob = @pg_loread($fd,$maxsize); |
|
416 | + $realblob = @pg_loread($fd, $maxsize); |
|
417 | 417 | @pg_loclose($fd); |
418 | - if ($hastrans) @pg_exec($this->_connectionID,"commit"); |
|
418 | + if ($hastrans) @pg_exec($this->_connectionID, "commit"); |
|
419 | 419 | return $realblob; |
420 | 420 | } |
421 | 421 | |
@@ -431,25 +431,25 @@ discard block |
||
431 | 431 | if (ADODB_PHPVER >= 0x4200) return pg_escape_bytea($blob); |
432 | 432 | |
433 | 433 | /*92=backslash, 0=null, 39=single-quote*/ |
434 | - $badch = array(chr(92),chr(0),chr(39)); # \ null ' |
|
435 | - $fixch = array('\\\\134','\\\\000','\\\\047'); |
|
436 | - return adodb_str_replace($badch,$fixch,$blob); |
|
434 | + $badch = array(chr(92), chr(0), chr(39)); # \ null ' |
|
435 | + $fixch = array('\\\\134', '\\\\000', '\\\\047'); |
|
436 | + return adodb_str_replace($badch, $fixch, $blob); |
|
437 | 437 | |
438 | 438 | // note that there is a pg_escape_bytea function only for php 4.2.0 or later |
439 | 439 | } |
440 | 440 | |
441 | 441 | // assumes bytea for blob, and varchar for clob |
442 | - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') |
|
442 | + function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB') |
|
443 | 443 | { |
444 | 444 | |
445 | 445 | if ($blobtype == 'CLOB') { |
446 | - return $this->Execute("UPDATE $table SET $column=" . $this->qstr($val) . " WHERE $where"); |
|
446 | + return $this->Execute("UPDATE $table SET $column=".$this->qstr($val)." WHERE $where"); |
|
447 | 447 | } |
448 | 448 | // do not use bind params which uses qstr(), as blobencode() already quotes data |
449 | 449 | return $this->Execute("UPDATE $table SET $column='".$this->BlobEncode($val)."'::bytea WHERE $where"); |
450 | 450 | } |
451 | 451 | |
452 | - function OffsetDate($dayFraction,$date=false) |
|
452 | + function OffsetDate($dayFraction, $date = false) |
|
453 | 453 | { |
454 | 454 | if (!$date) $date = $this->sysDate; |
455 | 455 | return "($date+interval'$dayFraction days')"; |
@@ -458,14 +458,14 @@ discard block |
||
458 | 458 | |
459 | 459 | // for schema support, pass in the $table param "$schema.$tabname". |
460 | 460 | // converts field names to lowercase, $upper is ignored |
461 | - function &MetaColumns($table,$normalize=true) |
|
461 | + function &MetaColumns($table, $normalize = true) |
|
462 | 462 | { |
463 | 463 | global $ADODB_FETCH_MODE; |
464 | 464 | //if tablenames are quoted, remove the quotes as the tablenames here are used for comparsion of content of fields in postgres system tables |
465 | - if (!empty($this->nameQuote) && !(strpos($table,$this->nameQuote)===false)) $table = str_replace($this->nameQuote,'',$table); |
|
465 | + if (!empty($this->nameQuote) && !(strpos($table, $this->nameQuote) === false)) $table = str_replace($this->nameQuote, '', $table); |
|
466 | 466 | $schema = false; |
467 | 467 | $false = false; |
468 | - $this->_findschema($table,$schema); |
|
468 | + $this->_findschema($table, $schema); |
|
469 | 469 | |
470 | 470 | if ($normalize) $table = strtolower($table); |
471 | 471 | |
@@ -473,8 +473,8 @@ discard block |
||
473 | 473 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
474 | 474 | if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); |
475 | 475 | |
476 | - if ($schema) $rs =& $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema)); |
|
477 | - else $rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table)); |
|
476 | + if ($schema) $rs = & $this->Execute(sprintf($this->metaColumnsSQL1, $table, $table, $schema)); |
|
477 | + else $rs = & $this->Execute(sprintf($this->metaColumnsSQL, $table, $table)); |
|
478 | 478 | if (isset($savem)) $this->SetFetchMode($savem); |
479 | 479 | $ADODB_FETCH_MODE = $save; |
480 | 480 | |
@@ -489,9 +489,9 @@ discard block |
||
489 | 489 | |
490 | 490 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
491 | 491 | |
492 | - $rskey = $this->Execute(sprintf($this->metaKeySQL,($table))); |
|
492 | + $rskey = $this->Execute(sprintf($this->metaKeySQL, ($table))); |
|
493 | 493 | // fetch all result in once for performance. |
494 | - $keys =& $rskey->GetArray(); |
|
494 | + $keys = & $rskey->GetArray(); |
|
495 | 495 | if (isset($savem)) $this->SetFetchMode($savem); |
496 | 496 | $ADODB_FETCH_MODE = $save; |
497 | 497 | |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | while (!$rsdef->EOF) { |
512 | 512 | $num = $rsdef->fields['num']; |
513 | 513 | $s = $rsdef->fields['def']; |
514 | - if (strpos($s,'::')===false && substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */ |
|
514 | + if (strpos($s, '::') === false && substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */ |
|
515 | 515 | $s = substr($s, 1); |
516 | 516 | $s = substr($s, 0, strlen($s) - 1); |
517 | 517 | } |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | $rsdef->MoveNext(); |
521 | 521 | } |
522 | 522 | } else { |
523 | - ADOConnection::outp( "==> SQL => " . $sql); |
|
523 | + ADOConnection::outp("==> SQL => ".$sql); |
|
524 | 524 | } |
525 | 525 | unset($rsdef); |
526 | 526 | } |
@@ -531,10 +531,10 @@ discard block |
||
531 | 531 | $fld->name = $rs->fields[0]; |
532 | 532 | $fld->type = $rs->fields[1]; |
533 | 533 | $fld->max_length = $rs->fields[2]; |
534 | - if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3]-4; |
|
534 | + if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3] - 4; |
|
535 | 535 | if ($fld->max_length <= 0) $fld->max_length = -1; |
536 | 536 | if ($fld->type == 'numeric') { |
537 | - $fld->scale = $fld->max_length & 0xFFFF; |
|
537 | + $fld->scale = $fld->max_length&0xFFFF; |
|
538 | 538 | $fld->max_length >>= 16; |
539 | 539 | } |
540 | 540 | // dannym |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | |
552 | 552 | // Freek |
553 | 553 | if (is_array($keys)) { |
554 | - foreach($keys as $key) { |
|
554 | + foreach ($keys as $key) { |
|
555 | 555 | if ($fld->name == $key['column_name'] AND $key['primary_key'] == 't') |
556 | 556 | $fld->primary_key = true; |
557 | 557 | if ($fld->name == $key['column_name'] AND $key['unique_key'] == 't') |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | |
573 | 573 | } |
574 | 574 | |
575 | - function &MetaIndexes ($table, $primary = FALSE) |
|
575 | + function &MetaIndexes($table, $primary = FALSE) |
|
576 | 576 | { |
577 | 577 | global $ADODB_FETCH_MODE; |
578 | 578 | |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | $table = str_replace($this->nameQuote, '', $table); |
581 | 581 | |
582 | 582 | $schema = false; |
583 | - $this->_findschema($table,$schema); |
|
583 | + $this->_findschema($table, $schema); |
|
584 | 584 | |
585 | 585 | if ($schema) { // requires pgsql 7.3+ - pg_namespace used. |
586 | 586 | $sql = ' |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | $savem = $this->SetFetchMode(FALSE); |
610 | 610 | } |
611 | 611 | |
612 | - $rs = $this->Execute(sprintf($sql,$table,$table,$schema)); |
|
612 | + $rs = $this->Execute(sprintf($sql, $table, $table, $schema)); |
|
613 | 613 | if (isset($savem)) { |
614 | 614 | $this->SetFetchMode($savem); |
615 | 615 | } |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | return $false; |
621 | 621 | } |
622 | 622 | |
623 | - $col_names = $this->MetaColumnNames($table,true); |
|
623 | + $col_names = $this->MetaColumnNames($table, true); |
|
624 | 624 | $indexes = array(); |
625 | 625 | while ($row = $rs->FetchRow()) { |
626 | 626 | $columns = array(); |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | // examples: |
642 | 642 | // $db->Connect("host=host1 user=user1 password=secret port=4341"); |
643 | 643 | // $db->Connect('host1','user1','secret'); |
644 | - function _connect($str,$user='',$pwd='',$db='',$ctype=0) |
|
644 | + function _connect($str, $user = '', $pwd = '', $db = '', $ctype = 0) |
|
645 | 645 | { |
646 | 646 | |
647 | 647 | if (!function_exists('pg_pconnect')) return null; |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | $pwd = adodb_addslashes($pwd); |
654 | 654 | if (strlen($db) == 0) $db = 'template1'; |
655 | 655 | $db = adodb_addslashes($db); |
656 | - if ($str) { |
|
656 | + if ($str) { |
|
657 | 657 | $host = explode(":", $str); |
658 | 658 | if ($host[0]) $str = "host=".adodb_addslashes($host[0]); |
659 | 659 | else $str = 'host=localhost'; |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | if (empty($ncnt)) $ncnt = 1; |
677 | 677 | else $ncnt += 1; |
678 | 678 | |
679 | - $str .= str_repeat(' ',$ncnt); |
|
679 | + $str .= str_repeat(' ', $ncnt); |
|
680 | 680 | } |
681 | 681 | $this->_connectionID = pg_connect($str); |
682 | 682 | } |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | |
688 | 688 | function _nconnect($argHostname, $argUsername, $argPassword, $argDatabaseName) |
689 | 689 | { |
690 | - return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName,-1); |
|
690 | + return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName, -1); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | // returns true or false |
@@ -695,14 +695,14 @@ discard block |
||
695 | 695 | // examples: |
696 | 696 | // $db->PConnect("host=host1 user=user1 password=secret port=4341"); |
697 | 697 | // $db->PConnect('host1','user1','secret'); |
698 | - function _pconnect($str,$user='',$pwd='',$db='') |
|
698 | + function _pconnect($str, $user = '', $pwd = '', $db = '') |
|
699 | 699 | { |
700 | - return $this->_connect($str,$user,$pwd,$db,1); |
|
700 | + return $this->_connect($str, $user, $pwd, $db, 1); |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | |
704 | 704 | // returns queryID or false |
705 | - function _query($sql,$inputarr) |
|
705 | + function _query($sql, $inputarr) |
|
706 | 706 | { |
707 | 707 | |
708 | 708 | if ($inputarr) { |
@@ -722,10 +722,10 @@ discard block |
||
722 | 722 | $plan = 'P'.md5($sql); |
723 | 723 | |
724 | 724 | $execp = ''; |
725 | - foreach($inputarr as $v) { |
|
725 | + foreach ($inputarr as $v) { |
|
726 | 726 | if ($execp) $execp .= ','; |
727 | 727 | if (is_string($v)) { |
728 | - if (strncmp($v,"'",1) !== 0) $execp .= $this->qstr($v); |
|
728 | + if (strncmp($v, "'", 1) !== 0) $execp .= $this->qstr($v); |
|
729 | 729 | } else { |
730 | 730 | $execp .= $v; |
731 | 731 | } |
@@ -734,11 +734,11 @@ discard block |
||
734 | 734 | if ($execp) $exsql = "EXECUTE $plan ($execp)"; |
735 | 735 | else $exsql = "EXECUTE $plan"; |
736 | 736 | |
737 | - $rez = @pg_exec($this->_connectionID,$exsql); |
|
737 | + $rez = @pg_exec($this->_connectionID, $exsql); |
|
738 | 738 | if (!$rez) { |
739 | 739 | # Perhaps plan does not exist? Prepare/compile plan. |
740 | 740 | $params = ''; |
741 | - foreach($inputarr as $v) { |
|
741 | + foreach ($inputarr as $v) { |
|
742 | 742 | if ($params) $params .= ','; |
743 | 743 | if (is_string($v)) { |
744 | 744 | $params .= 'VARCHAR'; |
@@ -748,25 +748,25 @@ discard block |
||
748 | 748 | $params .= "REAL"; |
749 | 749 | } |
750 | 750 | } |
751 | - $sqlarr = explode('?',$sql); |
|
751 | + $sqlarr = explode('?', $sql); |
|
752 | 752 | //print_r($sqlarr); |
753 | 753 | $sql = ''; |
754 | 754 | $i = 1; |
755 | - foreach($sqlarr as $v) { |
|
755 | + foreach ($sqlarr as $v) { |
|
756 | 756 | $sql .= $v.' $'.$i; |
757 | 757 | $i++; |
758 | 758 | } |
759 | - $s = "PREPARE $plan ($params) AS ".substr($sql,0,strlen($sql)-2); |
|
759 | + $s = "PREPARE $plan ($params) AS ".substr($sql, 0, strlen($sql) - 2); |
|
760 | 760 | //adodb_pr($s); |
761 | - pg_exec($this->_connectionID,$s); |
|
761 | + pg_exec($this->_connectionID, $s); |
|
762 | 762 | echo $this->ErrorMsg(); |
763 | 763 | } |
764 | 764 | |
765 | - $rez = pg_exec($this->_connectionID,$exsql); |
|
765 | + $rez = pg_exec($this->_connectionID, $exsql); |
|
766 | 766 | } else { |
767 | 767 | $this->_errorMsg = false; |
768 | 768 | //adodb_backtrace(); |
769 | - $rez = pg_exec($this->_connectionID,$sql); |
|
769 | + $rez = pg_exec($this->_connectionID, $sql); |
|
770 | 770 | } |
771 | 771 | // check if no data returned, then no need to create real recordset |
772 | 772 | if ($rez && pg_numfields($rez) <= 0) { |
@@ -829,7 +829,7 @@ discard block |
||
829 | 829 | */ |
830 | 830 | function CharMax() |
831 | 831 | { |
832 | - return 1000000000; // should be 1 Gb? |
|
832 | + return 1000000000; // should be 1 Gb? |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /* |
@@ -847,11 +847,11 @@ discard block |
||
847 | 847 | Class Name: Recordset |
848 | 848 | --------------------------------------------------------------------------------------*/ |
849 | 849 | |
850 | -class ADORecordSet_postgres64 extends ADORecordSet{ |
|
850 | +class ADORecordSet_postgres64 extends ADORecordSet { |
|
851 | 851 | var $_blobArr; |
852 | 852 | var $databaseType = "postgres64"; |
853 | 853 | var $canSeek = true; |
854 | - function ADORecordSet_postgres64($queryID,$mode=false) |
|
854 | + function ADORecordSet_postgres64($queryID, $mode = false) |
|
855 | 855 | { |
856 | 856 | if ($mode === false) { |
857 | 857 | global $ADODB_FETCH_MODE; |
@@ -870,10 +870,10 @@ discard block |
||
870 | 870 | $this->ADORecordSet($queryID); |
871 | 871 | } |
872 | 872 | |
873 | - function &GetRowAssoc($upper=true) |
|
873 | + function &GetRowAssoc($upper = true) |
|
874 | 874 | { |
875 | 875 | if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $this->fields; |
876 | - $row =& ADORecordSet::GetRowAssoc($upper); |
|
876 | + $row = & ADORecordSet::GetRowAssoc($upper); |
|
877 | 877 | return $row; |
878 | 878 | } |
879 | 879 | |
@@ -881,15 +881,15 @@ discard block |
||
881 | 881 | { |
882 | 882 | global $ADODB_COUNTRECS; |
883 | 883 | $qid = $this->_queryID; |
884 | - $this->_numOfRows = ($ADODB_COUNTRECS)? @pg_numrows($qid):-1; |
|
884 | + $this->_numOfRows = ($ADODB_COUNTRECS) ? @pg_numrows($qid) : -1; |
|
885 | 885 | $this->_numOfFields = @pg_numfields($qid); |
886 | 886 | |
887 | 887 | // cache types for blob decode check |
888 | 888 | // apparently pg_fieldtype actually performs an sql query on the database to get the type. |
889 | 889 | if (empty($this->connection->noBlobs)) |
890 | - for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { |
|
891 | - if (pg_fieldtype($qid,$i) == 'bytea') { |
|
892 | - $this->_blobArr[$i] = pg_fieldname($qid,$i); |
|
890 | + for ($i = 0, $max = $this->_numOfFields; $i < $max; $i++) { |
|
891 | + if (pg_fieldtype($qid, $i) == 'bytea') { |
|
892 | + $this->_blobArr[$i] = pg_fieldname($qid, $i); |
|
893 | 893 | } |
894 | 894 | } |
895 | 895 | } |
@@ -901,7 +901,7 @@ discard block |
||
901 | 901 | |
902 | 902 | if (!$this->bind) { |
903 | 903 | $this->bind = array(); |
904 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
904 | + for ($i = 0; $i < $this->_numOfFields; $i++) { |
|
905 | 905 | $o = $this->FetchField($i); |
906 | 906 | $this->bind[strtoupper($o->name)] = $i; |
907 | 907 | } |
@@ -913,16 +913,16 @@ discard block |
||
913 | 913 | { |
914 | 914 | // offsets begin at 0 |
915 | 915 | |
916 | - $o= new ADOFieldObject(); |
|
917 | - $o->name = @pg_fieldname($this->_queryID,$off); |
|
918 | - $o->type = @pg_fieldtype($this->_queryID,$off); |
|
919 | - $o->max_length = @pg_fieldsize($this->_queryID,$off); |
|
916 | + $o = new ADOFieldObject(); |
|
917 | + $o->name = @pg_fieldname($this->_queryID, $off); |
|
918 | + $o->type = @pg_fieldtype($this->_queryID, $off); |
|
919 | + $o->max_length = @pg_fieldsize($this->_queryID, $off); |
|
920 | 920 | return $o; |
921 | 921 | } |
922 | 922 | |
923 | 923 | function _seek($row) |
924 | 924 | { |
925 | - return @pg_fetch_row($this->_queryID,$row); |
|
925 | + return @pg_fetch_row($this->_queryID, $row); |
|
926 | 926 | } |
927 | 927 | |
928 | 928 | function _decode($blob) |
@@ -934,12 +934,12 @@ discard block |
||
934 | 934 | function _fixblobs() |
935 | 935 | { |
936 | 936 | if ($this->fetchMode == PGSQL_NUM || $this->fetchMode == PGSQL_BOTH) { |
937 | - foreach($this->_blobArr as $k => $v) { |
|
937 | + foreach ($this->_blobArr as $k => $v) { |
|
938 | 938 | $this->fields[$k] = ADORecordSet_postgres64::_decode($this->fields[$k]); |
939 | 939 | } |
940 | 940 | } |
941 | 941 | if ($this->fetchMode == PGSQL_ASSOC || $this->fetchMode == PGSQL_BOTH) { |
942 | - foreach($this->_blobArr as $k => $v) { |
|
942 | + foreach ($this->_blobArr as $k => $v) { |
|
943 | 943 | $this->fields[$v] = ADORecordSet_postgres64::_decode($this->fields[$v]); |
944 | 944 | } |
945 | 945 | } |
@@ -951,7 +951,7 @@ discard block |
||
951 | 951 | if (!$this->EOF) { |
952 | 952 | $this->_currentRow++; |
953 | 953 | if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) { |
954 | - $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); |
|
954 | + $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow, $this->fetchMode); |
|
955 | 955 | if (is_array($this->fields) && $this->fields) { |
956 | 956 | if (isset($this->_blobArr)) $this->_fixblobs(); |
957 | 957 | return true; |
@@ -969,7 +969,7 @@ discard block |
||
969 | 969 | if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0) |
970 | 970 | return false; |
971 | 971 | |
972 | - $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); |
|
972 | + $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow, $this->fetchMode); |
|
973 | 973 | |
974 | 974 | if ($this->fields && isset($this->_blobArr)) $this->_fixblobs(); |
975 | 975 | |
@@ -981,7 +981,7 @@ discard block |
||
981 | 981 | return @pg_freeresult($this->_queryID); |
982 | 982 | } |
983 | 983 | |
984 | - function MetaType($t,$len=-1,$fieldobj=false) |
|
984 | + function MetaType($t, $len = -1, $fieldobj = false) |
|
985 | 985 | { |
986 | 986 | if (is_object($t)) { |
987 | 987 | $fieldobj = $t; |
@@ -43,18 +43,29 @@ discard block |
||
43 | 43 | */ |
44 | 44 | |
45 | 45 | // security - hide paths |
46 | -if (!defined('ADODB_DIR')) die(); |
|
46 | +if (!defined('ADODB_DIR')) |
|
47 | +{ |
|
48 | + die(); |
|
49 | +} |
|
47 | 50 | |
48 | 51 | function adodb_addslashes($s) |
49 | 52 | { |
50 | 53 | $len = strlen($s); |
51 | - if ($len == 0) return "''"; |
|
52 | - if (strncmp($s,"'",1) === 0 && substr(s,$len-1) == "'") return $s; // already quoted |
|
54 | + if ($len == 0) |
|
55 | + { |
|
56 | + return "''"; |
|
57 | + } |
|
58 | + if (strncmp($s,"'",1) === 0 && substr(s,$len-1) == "'") |
|
59 | + { |
|
60 | + return $s; |
|
61 | + } |
|
62 | + // already quoted |
|
53 | 63 | |
54 | 64 | return "'".addslashes($s)."'"; |
55 | 65 | } |
56 | 66 | |
57 | -class ADODB_postgres64 extends ADOConnection{ |
|
67 | +class ADODB_postgres64 extends ADOConnection |
|
68 | +{ |
|
58 | 69 | var $databaseType = 'postgres64'; |
59 | 70 | var $dataProvider = 'postgres'; |
60 | 71 | var $hasInsertID = true; |
@@ -123,7 +134,10 @@ discard block |
||
123 | 134 | |
124 | 135 | function ServerInfo() |
125 | 136 | { |
126 | - if (isset($this->version)) return $this->version; |
|
137 | + if (isset($this->version)) |
|
138 | + { |
|
139 | + return $this->version; |
|
140 | + } |
|
127 | 141 | |
128 | 142 | $arr['description'] = $this->GetOne("select version()"); |
129 | 143 | $arr['version'] = ADOConnection::_findvers($arr['description']); |
@@ -140,10 +154,14 @@ discard block |
||
140 | 154 | function pg_insert_id($tablename,$fieldname) |
141 | 155 | { |
142 | 156 | $result=pg_exec($this->_connectionID, "SELECT last_value FROM ${tablename}_${fieldname}_seq"); |
143 | - if ($result) { |
|
157 | + if ($result) |
|
158 | + { |
|
144 | 159 | $arr = @pg_fetch_row($result,0); |
145 | 160 | pg_freeresult($result); |
146 | - if (isset($arr[0])) return $arr[0]; |
|
161 | + if (isset($arr[0])) |
|
162 | + { |
|
163 | + return $arr[0]; |
|
164 | + } |
|
147 | 165 | } |
148 | 166 | return false; |
149 | 167 | } |
@@ -156,22 +174,29 @@ discard block |
||
156 | 174 | { |
157 | 175 | if ($try_oid) |
158 | 176 | { |
159 | - if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; |
|
177 | + if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') |
|
178 | + { |
|
179 | + return false; |
|
180 | + } |
|
160 | 181 | $oid = pg_getlastoid($this->_resultid); |
161 | 182 | } |
162 | 183 | else |
163 | 184 | { |
164 | 185 | $oid = false; |
165 | 186 | } |
166 | - if ($oid === false && $table && $column) // table might not use oid's, default for 8.1+ |
|
187 | + if ($oid === false && $table && $column) |
|
188 | + { |
|
189 | + // table might not use oid's, default for 8.1+ |
|
167 | 190 | { |
168 | 191 | // try the standard sequence name first, due to table renames etc. this might not be the correct one |
169 | 192 | if (!($ret = $this->GetOne($sql='SELECT currval('.$this->qstr($table.'_'.$column.'_seq').')'))) { |
170 | 193 | // now we read the sequence name from the database itself, that is a lot slower! |
171 | 194 | $cols = $this->MetaColumns($table); |
195 | + } |
|
172 | 196 | $fld = $cols[strtoupper($column)]; |
173 | 197 | if ($fld->primary_key && $fld->has_default && |
174 | - preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$fld->default_value,$matches)) { |
|
198 | + preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$fld->default_value,$matches)) |
|
199 | + { |
|
175 | 200 | $ret = $this->GetOne($sql='SELECT currval('.$this->qstr($matches[1]).')'); |
176 | 201 | } |
177 | 202 | } |
@@ -185,7 +210,10 @@ discard block |
||
185 | 210 | // Warning: This compilation does not support pg_cmdtuples() in d:/inetpub/wwwroot/php/adodb/adodb-postgres.inc.php on line 44 |
186 | 211 | function _affectedrows() |
187 | 212 | { |
188 | - if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; |
|
213 | + if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') |
|
214 | + { |
|
215 | + return false; |
|
216 | + } |
|
189 | 217 | return pg_cmdtuples($this->_resultid); |
190 | 218 | } |
191 | 219 | |
@@ -193,22 +221,34 @@ discard block |
||
193 | 221 | // returns true/false |
194 | 222 | function BeginTrans() |
195 | 223 | { |
196 | - if ($this->transOff) return true; |
|
224 | + if ($this->transOff) |
|
225 | + { |
|
226 | + return true; |
|
227 | + } |
|
197 | 228 | $this->transCnt += 1; |
198 | 229 | return @pg_Exec($this->_connectionID, "begin"); |
199 | 230 | } |
200 | 231 | |
201 | 232 | function RowLock($tables,$where,$flds='1 as ignore') |
202 | 233 | { |
203 | - if (!$this->transCnt) $this->BeginTrans(); |
|
234 | + if (!$this->transCnt) |
|
235 | + { |
|
236 | + $this->BeginTrans(); |
|
237 | + } |
|
204 | 238 | return $this->GetOne("select $flds from $tables where $where for update"); |
205 | 239 | } |
206 | 240 | |
207 | 241 | // returns true/false. |
208 | 242 | function CommitTrans($ok=true) |
209 | 243 | { |
210 | - if ($this->transOff) return true; |
|
211 | - if (!$ok) return $this->RollbackTrans(); |
|
244 | + if ($this->transOff) |
|
245 | + { |
|
246 | + return true; |
|
247 | + } |
|
248 | + if (!$ok) |
|
249 | + { |
|
250 | + return $this->RollbackTrans(); |
|
251 | + } |
|
212 | 252 | |
213 | 253 | $this->transCnt -= 1; |
214 | 254 | return @pg_Exec($this->_connectionID, "commit"); |
@@ -217,7 +257,10 @@ discard block |
||
217 | 257 | // returns true/false |
218 | 258 | function RollbackTrans() |
219 | 259 | { |
220 | - if ($this->transOff) return true; |
|
260 | + if ($this->transOff) |
|
261 | + { |
|
262 | + return true; |
|
263 | + } |
|
221 | 264 | $this->transCnt -= 1; |
222 | 265 | return @pg_Exec($this->_connectionID, "rollback"); |
223 | 266 | } |
@@ -225,29 +268,35 @@ discard block |
||
225 | 268 | function &MetaTables($ttype=false,$showSchema=false,$mask=false) |
226 | 269 | { |
227 | 270 | $info = $this->ServerInfo(); |
228 | - if ($info['version'] >= 7.3) { |
|
271 | + if ($info['version'] >= 7.3) |
|
272 | + { |
|
229 | 273 | $this->metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' |
230 | 274 | and schemaname not in ( 'pg_catalog','information_schema') |
231 | 275 | union |
232 | 276 | select viewname,'V' from pg_views where viewname not like 'pg\_%' and schemaname not in ( 'pg_catalog','information_schema') "; |
233 | 277 | } |
234 | - if ($mask) { |
|
278 | + if ($mask) |
|
279 | + { |
|
235 | 280 | $save = $this->metaTablesSQL; |
236 | 281 | $mask = $this->qstr(strtolower($mask)); |
237 | 282 | if ($info['version']>=7.3) |
238 | - $this->metaTablesSQL = " |
|
283 | + { |
|
284 | + $this->metaTablesSQL = " |
|
239 | 285 | select tablename,'T' from pg_tables where tablename like $mask and schemaname not in ( 'pg_catalog','information_schema') |
240 | 286 | union |
241 | 287 | select viewname,'V' from pg_views where viewname like $mask and schemaname not in ( 'pg_catalog','information_schema') "; |
242 | - else |
|
243 | - $this->metaTablesSQL = " |
|
288 | + } |
|
289 | + else { |
|
290 | + $this->metaTablesSQL = " |
|
244 | 291 | select tablename,'T' from pg_tables where tablename like $mask |
245 | 292 | union |
246 | 293 | select viewname,'V' from pg_views where viewname like $mask"; |
294 | + } |
|
247 | 295 | } |
248 | 296 | $ret =& ADOConnection::MetaTables($ttype,$showSchema); |
249 | 297 | |
250 | - if ($mask) { |
|
298 | + if ($mask) |
|
299 | + { |
|
251 | 300 | $this->metaTablesSQL = $save; |
252 | 301 | } |
253 | 302 | return $ret; |
@@ -256,16 +305,23 @@ discard block |
||
256 | 305 | // if magic quotes disabled, use pg_escape_string() |
257 | 306 | function qstr($s,$magic_quotes=false) |
258 | 307 | { |
259 | - if (is_bool($s)) return $s ? 'true' : 'false'; |
|
308 | + if (is_bool($s)) |
|
309 | + { |
|
310 | + return $s ? 'true' : 'false'; |
|
311 | + } |
|
260 | 312 | |
261 | - if (!$magic_quotes) { |
|
262 | - if (ADODB_PHPVER >= 0x5200) { |
|
313 | + if (!$magic_quotes) |
|
314 | + { |
|
315 | + if (ADODB_PHPVER >= 0x5200) |
|
316 | + { |
|
263 | 317 | return "'".pg_escape_string($this->_connectionID,$s)."'"; |
264 | 318 | } |
265 | - if (ADODB_PHPVER >= 0x4200) { |
|
319 | + if (ADODB_PHPVER >= 0x4200) |
|
320 | + { |
|
266 | 321 | return "'".pg_escape_string($s)."'"; |
267 | 322 | } |
268 | - if ($this->replaceQuote[0] == '\\'){ |
|
323 | + if ($this->replaceQuote[0] == '\\') |
|
324 | + { |
|
269 | 325 | $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\\000"),$s); |
270 | 326 | } |
271 | 327 | return "'".str_replace("'",$this->replaceQuote,$s)."'"; |
@@ -280,13 +336,18 @@ discard block |
||
280 | 336 | // Format date column in sql string given an input format that understands Y M D |
281 | 337 | function SQLDate($fmt, $col=false) |
282 | 338 | { |
283 | - if (!$col) $col = $this->sysTimeStamp; |
|
339 | + if (!$col) |
|
340 | + { |
|
341 | + $col = $this->sysTimeStamp; |
|
342 | + } |
|
284 | 343 | $s = 'TO_CHAR('.$col.",'"; |
285 | 344 | |
286 | 345 | $len = strlen($fmt); |
287 | - for ($i=0; $i < $len; $i++) { |
|
346 | + for ($i=0; $i < $len; $i++) |
|
347 | + { |
|
288 | 348 | $ch = $fmt[$i]; |
289 | - switch($ch) { |
|
349 | + switch($ch) |
|
350 | + { |
|
290 | 351 | case 'Y': |
291 | 352 | case 'y': |
292 | 353 | $s .= 'YYYY'; |
@@ -339,12 +400,18 @@ discard block |
||
339 | 400 | |
340 | 401 | default: |
341 | 402 | // handle escape characters... |
342 | - if ($ch == '\\') { |
|
403 | + if ($ch == '\\') |
|
404 | + { |
|
343 | 405 | $i++; |
344 | 406 | $ch = substr($fmt,$i,1); |
345 | 407 | } |
346 | - if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; |
|
347 | - else $s .= '"'.$ch.'"'; |
|
408 | + if (strpos('-/.:;, ',$ch) !== false) |
|
409 | + { |
|
410 | + $s .= $ch; |
|
411 | + } |
|
412 | + else { |
|
413 | + $s .= '"'.$ch.'"'; |
|
414 | + } |
|
348 | 415 | |
349 | 416 | } |
350 | 417 | } |
@@ -386,7 +453,10 @@ discard block |
||
386 | 453 | */ |
387 | 454 | function GuessOID($oid) |
388 | 455 | { |
389 | - if (strlen($oid)>16) return false; |
|
456 | + if (strlen($oid)>16) |
|
457 | + { |
|
458 | + return false; |
|
459 | + } |
|
390 | 460 | return is_numeric($oid); |
391 | 461 | } |
392 | 462 | |
@@ -404,18 +474,34 @@ discard block |
||
404 | 474 | */ |
405 | 475 | function BlobDecode($blob,$maxsize=false,$hastrans=true) |
406 | 476 | { |
407 | - if (!$this->GuessOID($blob)) return $blob; |
|
477 | + if (!$this->GuessOID($blob)) |
|
478 | + { |
|
479 | + return $blob; |
|
480 | + } |
|
408 | 481 | |
409 | - if ($hastrans) @pg_exec($this->_connectionID,"begin"); |
|
482 | + if ($hastrans) |
|
483 | + { |
|
484 | + @pg_exec($this->_connectionID,"begin"); |
|
485 | + } |
|
410 | 486 | $fd = @pg_lo_open($this->_connectionID,$blob,"r"); |
411 | - if ($fd === false) { |
|
412 | - if ($hastrans) @pg_exec($this->_connectionID,"commit"); |
|
487 | + if ($fd === false) |
|
488 | + { |
|
489 | + if ($hastrans) |
|
490 | + { |
|
491 | + @pg_exec($this->_connectionID,"commit"); |
|
492 | + } |
|
413 | 493 | return $blob; |
414 | 494 | } |
415 | - if (!$maxsize) $maxsize = $this->maxblobsize; |
|
495 | + if (!$maxsize) |
|
496 | + { |
|
497 | + $maxsize = $this->maxblobsize; |
|
498 | + } |
|
416 | 499 | $realblob = @pg_loread($fd,$maxsize); |
417 | 500 | @pg_loclose($fd); |
418 | - if ($hastrans) @pg_exec($this->_connectionID,"commit"); |
|
501 | + if ($hastrans) |
|
502 | + { |
|
503 | + @pg_exec($this->_connectionID,"commit"); |
|
504 | + } |
|
419 | 505 | return $realblob; |
420 | 506 | } |
421 | 507 | |
@@ -428,7 +514,10 @@ discard block |
||
428 | 514 | */ |
429 | 515 | function BlobEncode($blob) |
430 | 516 | { |
431 | - if (ADODB_PHPVER >= 0x4200) return pg_escape_bytea($blob); |
|
517 | + if (ADODB_PHPVER >= 0x4200) |
|
518 | + { |
|
519 | + return pg_escape_bytea($blob); |
|
520 | + } |
|
432 | 521 | |
433 | 522 | /*92=backslash, 0=null, 39=single-quote*/ |
434 | 523 | $badch = array(chr(92),chr(0),chr(39)); # \ null ' |
@@ -442,7 +531,8 @@ discard block |
||
442 | 531 | function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') |
443 | 532 | { |
444 | 533 | |
445 | - if ($blobtype == 'CLOB') { |
|
534 | + if ($blobtype == 'CLOB') |
|
535 | + { |
|
446 | 536 | return $this->Execute("UPDATE $table SET $column=" . $this->qstr($val) . " WHERE $where"); |
447 | 537 | } |
448 | 538 | // do not use bind params which uses qstr(), as blobencode() already quotes data |
@@ -451,7 +541,10 @@ discard block |
||
451 | 541 | |
452 | 542 | function OffsetDate($dayFraction,$date=false) |
453 | 543 | { |
454 | - if (!$date) $date = $this->sysDate; |
|
544 | + if (!$date) |
|
545 | + { |
|
546 | + $date = $this->sysDate; |
|
547 | + } |
|
455 | 548 | return "($date+interval'$dayFraction days')"; |
456 | 549 | } |
457 | 550 | |
@@ -462,26 +555,45 @@ discard block |
||
462 | 555 | { |
463 | 556 | global $ADODB_FETCH_MODE; |
464 | 557 | //if tablenames are quoted, remove the quotes as the tablenames here are used for comparsion of content of fields in postgres system tables |
465 | - if (!empty($this->nameQuote) && !(strpos($table,$this->nameQuote)===false)) $table = str_replace($this->nameQuote,'',$table); |
|
558 | + if (!empty($this->nameQuote) && !(strpos($table,$this->nameQuote)===false)) |
|
559 | + { |
|
560 | + $table = str_replace($this->nameQuote,'',$table); |
|
561 | + } |
|
466 | 562 | $schema = false; |
467 | 563 | $false = false; |
468 | 564 | $this->_findschema($table,$schema); |
469 | 565 | |
470 | - if ($normalize) $table = strtolower($table); |
|
566 | + if ($normalize) |
|
567 | + { |
|
568 | + $table = strtolower($table); |
|
569 | + } |
|
471 | 570 | |
472 | 571 | $save = $ADODB_FETCH_MODE; |
473 | 572 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
474 | - if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); |
|
573 | + if ($this->fetchMode !== false) |
|
574 | + { |
|
575 | + $savem = $this->SetFetchMode(false); |
|
576 | + } |
|
475 | 577 | |
476 | - if ($schema) $rs =& $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema)); |
|
477 | - else $rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table)); |
|
478 | - if (isset($savem)) $this->SetFetchMode($savem); |
|
578 | + if ($schema) |
|
579 | + { |
|
580 | + $rs =& $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema)); |
|
581 | + } |
|
582 | + else { |
|
583 | + $rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table)); |
|
584 | + } |
|
585 | + if (isset($savem)) |
|
586 | + { |
|
587 | + $this->SetFetchMode($savem); |
|
588 | + } |
|
479 | 589 | $ADODB_FETCH_MODE = $save; |
480 | 590 | |
481 | - if ($rs === false) { |
|
591 | + if ($rs === false) |
|
592 | + { |
|
482 | 593 | return $false; |
483 | 594 | } |
484 | - if (!empty($this->metaKeySQL)) { |
|
595 | + if (!empty($this->metaKeySQL)) |
|
596 | + { |
|
485 | 597 | // If we want the primary keys, we have to issue a separate query |
486 | 598 | // Of course, a modified version of the metaColumnsSQL query using a |
487 | 599 | // LEFT JOIN would have been much more elegant, but postgres does |
@@ -492,7 +604,10 @@ discard block |
||
492 | 604 | $rskey = $this->Execute(sprintf($this->metaKeySQL,($table))); |
493 | 605 | // fetch all result in once for performance. |
494 | 606 | $keys =& $rskey->GetArray(); |
495 | - if (isset($savem)) $this->SetFetchMode($savem); |
|
607 | + if (isset($savem)) |
|
608 | + { |
|
609 | + $this->SetFetchMode($savem); |
|
610 | + } |
|
496 | 611 | $ADODB_FETCH_MODE = $save; |
497 | 612 | |
498 | 613 | $rskey->Close(); |
@@ -500,18 +615,26 @@ discard block |
||
500 | 615 | } |
501 | 616 | |
502 | 617 | $rsdefa = array(); |
503 | - if (!empty($this->metaDefaultsSQL)) { |
|
618 | + if (!empty($this->metaDefaultsSQL)) |
|
619 | + { |
|
504 | 620 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
505 | 621 | $sql = sprintf($this->metaDefaultsSQL, ($table)); |
506 | 622 | $rsdef = $this->Execute($sql); |
507 | - if (isset($savem)) $this->SetFetchMode($savem); |
|
623 | + if (isset($savem)) |
|
624 | + { |
|
625 | + $this->SetFetchMode($savem); |
|
626 | + } |
|
508 | 627 | $ADODB_FETCH_MODE = $save; |
509 | 628 | |
510 | - if ($rsdef) { |
|
511 | - while (!$rsdef->EOF) { |
|
629 | + if ($rsdef) |
|
630 | + { |
|
631 | + while (!$rsdef->EOF) |
|
632 | + { |
|
512 | 633 | $num = $rsdef->fields['num']; |
513 | 634 | $s = $rsdef->fields['def']; |
514 | - if (strpos($s,'::')===false && substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */ |
|
635 | + if (strpos($s,'::')===false && substr($s, 0, 1) == "'") |
|
636 | + { |
|
637 | +/* quoted strings hack... for now... fixme */ |
|
515 | 638 | $s = substr($s, 1); |
516 | 639 | $s = substr($s, 0, strlen($s) - 1); |
517 | 640 | } |
@@ -519,56 +642,83 @@ discard block |
||
519 | 642 | $rsdefa[$num] = $s; |
520 | 643 | $rsdef->MoveNext(); |
521 | 644 | } |
522 | - } else { |
|
645 | + } |
|
646 | + else |
|
647 | + { |
|
523 | 648 | ADOConnection::outp( "==> SQL => " . $sql); |
524 | 649 | } |
525 | 650 | unset($rsdef); |
526 | 651 | } |
527 | 652 | |
528 | 653 | $retarr = array(); |
529 | - while (!$rs->EOF) { |
|
654 | + while (!$rs->EOF) |
|
655 | + { |
|
530 | 656 | $fld = new ADOFieldObject(); |
531 | 657 | $fld->name = $rs->fields[0]; |
532 | 658 | $fld->type = $rs->fields[1]; |
533 | 659 | $fld->max_length = $rs->fields[2]; |
534 | - if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3]-4; |
|
535 | - if ($fld->max_length <= 0) $fld->max_length = -1; |
|
536 | - if ($fld->type == 'numeric') { |
|
660 | + if ($fld->max_length <= 0) |
|
661 | + { |
|
662 | + $fld->max_length = $rs->fields[3]-4; |
|
663 | + } |
|
664 | + if ($fld->max_length <= 0) |
|
665 | + { |
|
666 | + $fld->max_length = -1; |
|
667 | + } |
|
668 | + if ($fld->type == 'numeric') |
|
669 | + { |
|
537 | 670 | $fld->scale = $fld->max_length & 0xFFFF; |
538 | 671 | $fld->max_length >>= 16; |
539 | 672 | } |
540 | 673 | // dannym |
541 | 674 | // 5 hasdefault; 6 num-of-column |
542 | 675 | $fld->has_default = ($rs->fields[5] == 't'); |
543 | - if ($fld->has_default) { |
|
676 | + if ($fld->has_default) |
|
677 | + { |
|
544 | 678 | $fld->default_value = $rsdefa[$rs->fields[6]]; |
545 | 679 | } |
546 | 680 | |
547 | 681 | //Freek |
548 | - if ($rs->fields[4] == 't') { |
|
682 | + if ($rs->fields[4] == 't') |
|
683 | + { |
|
549 | 684 | $fld->not_null = true; |
550 | 685 | } |
551 | 686 | |
552 | 687 | // Freek |
553 | - if (is_array($keys)) { |
|
554 | - foreach($keys as $key) { |
|
688 | + if (is_array($keys)) |
|
689 | + { |
|
690 | + foreach($keys as $key) |
|
691 | + { |
|
555 | 692 | if ($fld->name == $key['column_name'] AND $key['primary_key'] == 't') |
556 | - $fld->primary_key = true; |
|
693 | + { |
|
694 | + $fld->primary_key = true; |
|
695 | + } |
|
557 | 696 | if ($fld->name == $key['column_name'] AND $key['unique_key'] == 't') |
558 | - $fld->unique = true; // What name is more compatible? |
|
697 | + { |
|
698 | + $fld->unique = true; |
|
699 | + } |
|
700 | + // What name is more compatible? |
|
559 | 701 | } |
560 | 702 | } |
561 | 703 | |
562 | - if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; |
|
563 | - else $retarr[($normalize) ? strtoupper($fld->name) : $fld->name] = $fld; |
|
704 | + if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) |
|
705 | + { |
|
706 | + $retarr[] = $fld; |
|
707 | + } |
|
708 | + else { |
|
709 | + $retarr[($normalize) ? strtoupper($fld->name) : $fld->name] = $fld; |
|
710 | + } |
|
564 | 711 | |
565 | 712 | $rs->MoveNext(); |
566 | 713 | } |
567 | 714 | $rs->Close(); |
568 | 715 | if (empty($retarr)) |
569 | - return $false; |
|
570 | - else |
|
571 | - return $retarr; |
|
716 | + { |
|
717 | + return $false; |
|
718 | + } |
|
719 | + else { |
|
720 | + return $retarr; |
|
721 | + } |
|
572 | 722 | |
573 | 723 | } |
574 | 724 | |
@@ -582,7 +732,9 @@ discard block |
||
582 | 732 | $schema = false; |
583 | 733 | $this->_findschema($table,$schema); |
584 | 734 | |
585 | - if ($schema) { // requires pgsql 7.3+ - pg_namespace used. |
|
735 | + if ($schema) |
|
736 | + { |
|
737 | +// requires pgsql 7.3+ - pg_namespace used. |
|
586 | 738 | $sql = ' |
587 | 739 | SELECT c.relname as "Name", i.indisunique as "Unique", i.indkey as "Columns" |
588 | 740 | FROM pg_catalog.pg_class c |
@@ -590,7 +742,9 @@ discard block |
||
590 | 742 | JOIN pg_catalog.pg_class c2 ON c2.oid=i.indrelid |
591 | 743 | ,pg_namespace n |
592 | 744 | WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\')) and c.relnamespace=c2.relnamespace and c.relnamespace=n.oid and n.nspname=\'%s\' AND i.indisprimary=false'; |
593 | - } else { |
|
745 | + } |
|
746 | + else |
|
747 | + { |
|
594 | 748 | $sql = ' |
595 | 749 | SELECT c.relname as "Name", i.indisunique as "Unique", i.indkey as "Columns" |
596 | 750 | FROM pg_catalog.pg_class c |
@@ -599,32 +753,38 @@ discard block |
||
599 | 753 | WHERE c2.relname=\'%s\' or c2.relname=lower(\'%s\')'; |
600 | 754 | } |
601 | 755 | |
602 | - if ($primary == FALSE) { |
|
756 | + if ($primary == FALSE) |
|
757 | + { |
|
603 | 758 | $sql .= ' AND i.indisprimary=false;'; |
604 | 759 | } |
605 | 760 | |
606 | 761 | $save = $ADODB_FETCH_MODE; |
607 | 762 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
608 | - if ($this->fetchMode !== FALSE) { |
|
763 | + if ($this->fetchMode !== FALSE) |
|
764 | + { |
|
609 | 765 | $savem = $this->SetFetchMode(FALSE); |
610 | 766 | } |
611 | 767 | |
612 | 768 | $rs = $this->Execute(sprintf($sql,$table,$table,$schema)); |
613 | - if (isset($savem)) { |
|
769 | + if (isset($savem)) |
|
770 | + { |
|
614 | 771 | $this->SetFetchMode($savem); |
615 | 772 | } |
616 | 773 | $ADODB_FETCH_MODE = $save; |
617 | 774 | |
618 | - if (!is_object($rs)) { |
|
775 | + if (!is_object($rs)) |
|
776 | + { |
|
619 | 777 | $false = false; |
620 | 778 | return $false; |
621 | 779 | } |
622 | 780 | |
623 | 781 | $col_names = $this->MetaColumnNames($table,true); |
624 | 782 | $indexes = array(); |
625 | - while ($row = $rs->FetchRow()) { |
|
783 | + while ($row = $rs->FetchRow()) |
|
784 | + { |
|
626 | 785 | $columns = array(); |
627 | - foreach (explode(' ', $row[2]) as $col) { |
|
786 | + foreach (explode(' ', $row[2]) as $col) |
|
787 | + { |
|
628 | 788 | $columns[] = $col_names[$col - 1]; |
629 | 789 | } |
630 | 790 | |
@@ -644,43 +804,85 @@ discard block |
||
644 | 804 | function _connect($str,$user='',$pwd='',$db='',$ctype=0) |
645 | 805 | { |
646 | 806 | |
647 | - if (!function_exists('pg_pconnect')) return null; |
|
807 | + if (!function_exists('pg_pconnect')) |
|
808 | + { |
|
809 | + return null; |
|
810 | + } |
|
648 | 811 | |
649 | 812 | $this->_errorMsg = false; |
650 | 813 | |
651 | - if ($user || $pwd || $db) { |
|
814 | + if ($user || $pwd || $db) |
|
815 | + { |
|
652 | 816 | $user = adodb_addslashes($user); |
653 | 817 | $pwd = adodb_addslashes($pwd); |
654 | - if (strlen($db) == 0) $db = 'template1'; |
|
818 | + if (strlen($db) == 0) |
|
819 | + { |
|
820 | + $db = 'template1'; |
|
821 | + } |
|
655 | 822 | $db = adodb_addslashes($db); |
656 | - if ($str) { |
|
823 | + if ($str) |
|
824 | + { |
|
657 | 825 | $host = explode(":", $str); |
658 | - if ($host[0]) $str = "host=".adodb_addslashes($host[0]); |
|
659 | - else $str = 'host=localhost'; |
|
660 | - if (isset($host[1])) $str .= " port=$host[1]"; |
|
661 | - else if (!empty($this->port)) $str .= " port=".$this->port; |
|
826 | + if ($host[0]) |
|
827 | + { |
|
828 | + $str = "host=".adodb_addslashes($host[0]); |
|
829 | + } |
|
830 | + else { |
|
831 | + $str = 'host=localhost'; |
|
832 | + } |
|
833 | + if (isset($host[1])) |
|
834 | + { |
|
835 | + $str .= " port=$host[1]"; |
|
836 | + } |
|
837 | + else if (!empty($this->port)) |
|
838 | + { |
|
839 | + $str .= " port=".$this->port; |
|
840 | + } |
|
662 | 841 | } |
663 | - if ($user) $str .= " user=".$user; |
|
664 | - if ($pwd) $str .= " password=".$pwd; |
|
665 | - if ($db) $str .= " dbname=".$db; |
|
842 | + if ($user) |
|
843 | + { |
|
844 | + $str .= " user=".$user; |
|
845 | + } |
|
846 | + if ($pwd) |
|
847 | + { |
|
848 | + $str .= " password=".$pwd; |
|
849 | + } |
|
850 | + if ($db) |
|
851 | + { |
|
852 | + $str .= " dbname=".$db; |
|
853 | + } |
|
666 | 854 | } |
667 | 855 | |
668 | 856 | //if ($user) $linea = "user=$user host=$linea password=$pwd dbname=$db port=5432"; |
669 | 857 | |
670 | - if ($ctype === 1) { // persistent |
|
858 | + if ($ctype === 1) |
|
859 | + { |
|
860 | +// persistent |
|
671 | 861 | $this->_connectionID = pg_pconnect($str); |
672 | - } else { |
|
673 | - if ($ctype === -1) { // nconnect, we trick pgsql ext by changing the connection str |
|
862 | + } |
|
863 | + else |
|
864 | + { |
|
865 | + if ($ctype === -1) |
|
866 | + { |
|
867 | +// nconnect, we trick pgsql ext by changing the connection str |
|
674 | 868 | static $ncnt; |
675 | 869 | |
676 | - if (empty($ncnt)) $ncnt = 1; |
|
677 | - else $ncnt += 1; |
|
870 | + if (empty($ncnt)) |
|
871 | + { |
|
872 | + $ncnt = 1; |
|
873 | + } |
|
874 | + else { |
|
875 | + $ncnt += 1; |
|
876 | + } |
|
678 | 877 | |
679 | 878 | $str .= str_repeat(' ',$ncnt); |
680 | 879 | } |
681 | 880 | $this->_connectionID = pg_connect($str); |
682 | 881 | } |
683 | - if ($this->_connectionID === false) return false; |
|
882 | + if ($this->_connectionID === false) |
|
883 | + { |
|
884 | + return false; |
|
885 | + } |
|
684 | 886 | $this->Execute("set datestyle='ISO'"); |
685 | 887 | return true; |
686 | 888 | } |
@@ -705,7 +907,8 @@ discard block |
||
705 | 907 | function _query($sql,$inputarr) |
706 | 908 | { |
707 | 909 | |
708 | - if ($inputarr) { |
|
910 | + if ($inputarr) |
|
911 | + { |
|
709 | 912 | /* |
710 | 913 | It appears that PREPARE/EXECUTE is slower for many queries. |
711 | 914 | |
@@ -722,29 +925,54 @@ discard block |
||
722 | 925 | $plan = 'P'.md5($sql); |
723 | 926 | |
724 | 927 | $execp = ''; |
725 | - foreach($inputarr as $v) { |
|
726 | - if ($execp) $execp .= ','; |
|
727 | - if (is_string($v)) { |
|
728 | - if (strncmp($v,"'",1) !== 0) $execp .= $this->qstr($v); |
|
729 | - } else { |
|
928 | + foreach($inputarr as $v) |
|
929 | + { |
|
930 | + if ($execp) |
|
931 | + { |
|
932 | + $execp .= ','; |
|
933 | + } |
|
934 | + if (is_string($v)) |
|
935 | + { |
|
936 | + if (strncmp($v,"'",1) !== 0) |
|
937 | + { |
|
938 | + $execp .= $this->qstr($v); |
|
939 | + } |
|
940 | + } |
|
941 | + else |
|
942 | + { |
|
730 | 943 | $execp .= $v; |
731 | 944 | } |
732 | 945 | } |
733 | 946 | |
734 | - if ($execp) $exsql = "EXECUTE $plan ($execp)"; |
|
735 | - else $exsql = "EXECUTE $plan"; |
|
947 | + if ($execp) |
|
948 | + { |
|
949 | + $exsql = "EXECUTE $plan ($execp)"; |
|
950 | + } |
|
951 | + else { |
|
952 | + $exsql = "EXECUTE $plan"; |
|
953 | + } |
|
736 | 954 | |
737 | 955 | $rez = @pg_exec($this->_connectionID,$exsql); |
738 | - if (!$rez) { |
|
956 | + if (!$rez) |
|
957 | + { |
|
739 | 958 | # Perhaps plan does not exist? Prepare/compile plan. |
740 | 959 | $params = ''; |
741 | - foreach($inputarr as $v) { |
|
742 | - if ($params) $params .= ','; |
|
743 | - if (is_string($v)) { |
|
960 | + foreach($inputarr as $v) |
|
961 | + { |
|
962 | + if ($params) |
|
963 | + { |
|
964 | + $params .= ','; |
|
965 | + } |
|
966 | + if (is_string($v)) |
|
967 | + { |
|
744 | 968 | $params .= 'VARCHAR'; |
745 | - } else if (is_integer($v)) { |
|
969 | + } |
|
970 | + else if (is_integer($v)) |
|
971 | + { |
|
746 | 972 | $params .= 'INTEGER'; |
747 | - } else { |
|
973 | + } |
|
974 | + else |
|
975 | + { |
|
748 | 976 | $params .= "REAL"; |
749 | 977 | } |
750 | 978 | } |
@@ -752,7 +980,8 @@ discard block |
||
752 | 980 | //print_r($sqlarr); |
753 | 981 | $sql = ''; |
754 | 982 | $i = 1; |
755 | - foreach($sqlarr as $v) { |
|
983 | + foreach($sqlarr as $v) |
|
984 | + { |
|
756 | 985 | $sql .= $v.' $'.$i; |
757 | 986 | $i++; |
758 | 987 | } |
@@ -763,14 +992,18 @@ discard block |
||
763 | 992 | } |
764 | 993 | |
765 | 994 | $rez = pg_exec($this->_connectionID,$exsql); |
766 | - } else { |
|
995 | + } |
|
996 | + else |
|
997 | + { |
|
767 | 998 | $this->_errorMsg = false; |
768 | 999 | //adodb_backtrace(); |
769 | 1000 | $rez = pg_exec($this->_connectionID,$sql); |
770 | 1001 | } |
771 | 1002 | // check if no data returned, then no need to create real recordset |
772 | - if ($rez && pg_numfields($rez) <= 0) { |
|
773 | - if (is_resource($this->_resultid) && get_resource_type($this->_resultid) === 'pgsql result') { |
|
1003 | + if ($rez && pg_numfields($rez) <= 0) |
|
1004 | + { |
|
1005 | + if (is_resource($this->_resultid) && get_resource_type($this->_resultid) === 'pgsql result') |
|
1006 | + { |
|
774 | 1007 | pg_freeresult($this->_resultid); |
775 | 1008 | } |
776 | 1009 | $this->_resultid = $rez; |
@@ -784,19 +1017,38 @@ discard block |
||
784 | 1017 | /* Returns: the last error message from previous database operation */ |
785 | 1018 | function ErrorMsg() |
786 | 1019 | { |
787 | - if ($this->_errorMsg !== false) return $this->_errorMsg; |
|
788 | - if (ADODB_PHPVER >= 0x4300) { |
|
789 | - if (!empty($this->_resultid)) { |
|
1020 | + if ($this->_errorMsg !== false) |
|
1021 | + { |
|
1022 | + return $this->_errorMsg; |
|
1023 | + } |
|
1024 | + if (ADODB_PHPVER >= 0x4300) |
|
1025 | + { |
|
1026 | + if (!empty($this->_resultid)) |
|
1027 | + { |
|
790 | 1028 | $this->_errorMsg = @pg_result_error($this->_resultid); |
791 | - if ($this->_errorMsg) return $this->_errorMsg; |
|
1029 | + if ($this->_errorMsg) |
|
1030 | + { |
|
1031 | + return $this->_errorMsg; |
|
1032 | + } |
|
792 | 1033 | } |
793 | 1034 | |
794 | - if (!empty($this->_connectionID)) { |
|
1035 | + if (!empty($this->_connectionID)) |
|
1036 | + { |
|
795 | 1037 | $this->_errorMsg = @pg_last_error($this->_connectionID); |
796 | - } else $this->_errorMsg = @pg_last_error(); |
|
797 | - } else { |
|
798 | - if (empty($this->_connectionID)) $this->_errorMsg = @pg_errormessage(); |
|
799 | - else $this->_errorMsg = @pg_errormessage($this->_connectionID); |
|
1038 | + } |
|
1039 | + else { |
|
1040 | + $this->_errorMsg = @pg_last_error(); |
|
1041 | + } |
|
1042 | + } |
|
1043 | + else |
|
1044 | + { |
|
1045 | + if (empty($this->_connectionID)) |
|
1046 | + { |
|
1047 | + $this->_errorMsg = @pg_errormessage(); |
|
1048 | + } |
|
1049 | + else { |
|
1050 | + $this->_errorMsg = @pg_errormessage($this->_connectionID); |
|
1051 | + } |
|
800 | 1052 | } |
801 | 1053 | return $this->_errorMsg; |
802 | 1054 | } |
@@ -804,7 +1056,8 @@ discard block |
||
804 | 1056 | function ErrorNo() |
805 | 1057 | { |
806 | 1058 | $e = $this->ErrorMsg(); |
807 | - if (strlen($e)) { |
|
1059 | + if (strlen($e)) |
|
1060 | + { |
|
808 | 1061 | return ADOConnection::MetaError($e); |
809 | 1062 | } |
810 | 1063 | return 0; |
@@ -813,8 +1066,12 @@ discard block |
||
813 | 1066 | // returns true or false |
814 | 1067 | function _close() |
815 | 1068 | { |
816 | - if ($this->transCnt) $this->RollbackTrans(); |
|
817 | - if ($this->_resultid) { |
|
1069 | + if ($this->transCnt) |
|
1070 | + { |
|
1071 | + $this->RollbackTrans(); |
|
1072 | + } |
|
1073 | + if ($this->_resultid) |
|
1074 | + { |
|
818 | 1075 | @pg_freeresult($this->_resultid); |
819 | 1076 | $this->_resultid = false; |
820 | 1077 | } |
@@ -847,13 +1104,15 @@ discard block |
||
847 | 1104 | Class Name: Recordset |
848 | 1105 | --------------------------------------------------------------------------------------*/ |
849 | 1106 | |
850 | -class ADORecordSet_postgres64 extends ADORecordSet{ |
|
1107 | +class ADORecordSet_postgres64 extends ADORecordSet |
|
1108 | +{ |
|
851 | 1109 | var $_blobArr; |
852 | 1110 | var $databaseType = "postgres64"; |
853 | 1111 | var $canSeek = true; |
854 | 1112 | function ADORecordSet_postgres64($queryID,$mode=false) |
855 | 1113 | { |
856 | - if ($mode === false) { |
|
1114 | + if ($mode === false) |
|
1115 | + { |
|
857 | 1116 | global $ADODB_FETCH_MODE; |
858 | 1117 | $mode = $ADODB_FETCH_MODE; |
859 | 1118 | } |
@@ -872,7 +1131,10 @@ discard block |
||
872 | 1131 | |
873 | 1132 | function &GetRowAssoc($upper=true) |
874 | 1133 | { |
875 | - if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $this->fields; |
|
1134 | + if ($this->fetchMode == PGSQL_ASSOC && !$upper) |
|
1135 | + { |
|
1136 | + return $this->fields; |
|
1137 | + } |
|
876 | 1138 | $row =& ADORecordSet::GetRowAssoc($upper); |
877 | 1139 | return $row; |
878 | 1140 | } |
@@ -887,8 +1149,13 @@ discard block |
||
887 | 1149 | // cache types for blob decode check |
888 | 1150 | // apparently pg_fieldtype actually performs an sql query on the database to get the type. |
889 | 1151 | if (empty($this->connection->noBlobs)) |
890 | - for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { |
|
891 | - if (pg_fieldtype($qid,$i) == 'bytea') { |
|
1152 | + { |
|
1153 | + for ($i=0, $max = $this->_numOfFields; |
|
1154 | + } |
|
1155 | + $i < $max; $i++) |
|
1156 | + { |
|
1157 | + if (pg_fieldtype($qid,$i) == 'bytea') |
|
1158 | + { |
|
892 | 1159 | $this->_blobArr[$i] = pg_fieldname($qid,$i); |
893 | 1160 | } |
894 | 1161 | } |
@@ -897,11 +1164,16 @@ discard block |
||
897 | 1164 | /* Use associative array to get fields array */ |
898 | 1165 | function Fields($colname) |
899 | 1166 | { |
900 | - if ($this->fetchMode != PGSQL_NUM) return @$this->fields[$colname]; |
|
1167 | + if ($this->fetchMode != PGSQL_NUM) |
|
1168 | + { |
|
1169 | + return @$this->fields[$colname]; |
|
1170 | + } |
|
901 | 1171 | |
902 | - if (!$this->bind) { |
|
1172 | + if (!$this->bind) |
|
1173 | + { |
|
903 | 1174 | $this->bind = array(); |
904 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
1175 | + for ($i=0; $i < $this->_numOfFields; $i++) |
|
1176 | + { |
|
905 | 1177 | $o = $this->FetchField($i); |
906 | 1178 | $this->bind[strtoupper($o->name)] = $i; |
907 | 1179 | } |
@@ -927,19 +1199,26 @@ discard block |
||
927 | 1199 | |
928 | 1200 | function _decode($blob) |
929 | 1201 | { |
930 | - if ($blob === NULL) return NULL; |
|
1202 | + if ($blob === NULL) |
|
1203 | + { |
|
1204 | + return NULL; |
|
1205 | + } |
|
931 | 1206 | return pg_unescape_bytea($blob); |
932 | 1207 | } |
933 | 1208 | |
934 | 1209 | function _fixblobs() |
935 | 1210 | { |
936 | - if ($this->fetchMode == PGSQL_NUM || $this->fetchMode == PGSQL_BOTH) { |
|
937 | - foreach($this->_blobArr as $k => $v) { |
|
1211 | + if ($this->fetchMode == PGSQL_NUM || $this->fetchMode == PGSQL_BOTH) |
|
1212 | + { |
|
1213 | + foreach($this->_blobArr as $k => $v) |
|
1214 | + { |
|
938 | 1215 | $this->fields[$k] = ADORecordSet_postgres64::_decode($this->fields[$k]); |
939 | 1216 | } |
940 | 1217 | } |
941 | - if ($this->fetchMode == PGSQL_ASSOC || $this->fetchMode == PGSQL_BOTH) { |
|
942 | - foreach($this->_blobArr as $k => $v) { |
|
1218 | + if ($this->fetchMode == PGSQL_ASSOC || $this->fetchMode == PGSQL_BOTH) |
|
1219 | + { |
|
1220 | + foreach($this->_blobArr as $k => $v) |
|
1221 | + { |
|
943 | 1222 | $this->fields[$v] = ADORecordSet_postgres64::_decode($this->fields[$v]); |
944 | 1223 | } |
945 | 1224 | } |
@@ -948,12 +1227,18 @@ discard block |
||
948 | 1227 | // 10% speedup to move MoveNext to child class |
949 | 1228 | function MoveNext() |
950 | 1229 | { |
951 | - if (!$this->EOF) { |
|
1230 | + if (!$this->EOF) |
|
1231 | + { |
|
952 | 1232 | $this->_currentRow++; |
953 | - if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) { |
|
1233 | + if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) |
|
1234 | + { |
|
954 | 1235 | $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); |
955 | - if (is_array($this->fields) && $this->fields) { |
|
956 | - if (isset($this->_blobArr)) $this->_fixblobs(); |
|
1236 | + if (is_array($this->fields) && $this->fields) |
|
1237 | + { |
|
1238 | + if (isset($this->_blobArr)) |
|
1239 | + { |
|
1240 | + $this->_fixblobs(); |
|
1241 | + } |
|
957 | 1242 | return true; |
958 | 1243 | } |
959 | 1244 | } |
@@ -967,11 +1252,16 @@ discard block |
||
967 | 1252 | { |
968 | 1253 | |
969 | 1254 | if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0) |
970 | - return false; |
|
1255 | + { |
|
1256 | + return false; |
|
1257 | + } |
|
971 | 1258 | |
972 | 1259 | $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); |
973 | 1260 | |
974 | - if ($this->fields && isset($this->_blobArr)) $this->_fixblobs(); |
|
1261 | + if ($this->fields && isset($this->_blobArr)) |
|
1262 | + { |
|
1263 | + $this->_fixblobs(); |
|
1264 | + } |
|
975 | 1265 | |
976 | 1266 | return (is_array($this->fields)); |
977 | 1267 | } |
@@ -983,12 +1273,14 @@ discard block |
||
983 | 1273 | |
984 | 1274 | function MetaType($t,$len=-1,$fieldobj=false) |
985 | 1275 | { |
986 | - if (is_object($t)) { |
|
1276 | + if (is_object($t)) |
|
1277 | + { |
|
987 | 1278 | $fieldobj = $t; |
988 | 1279 | $t = $fieldobj->type; |
989 | 1280 | $len = $fieldobj->max_length; |
990 | 1281 | } |
991 | - switch (strtoupper($t)) { |
|
1282 | + switch (strtoupper($t)) |
|
1283 | + { |
|
992 | 1284 | case 'MONEY': // stupid, postgres expects money to be a string |
993 | 1285 | case 'INTERVAL': |
994 | 1286 | case 'CHAR': |
@@ -998,7 +1290,10 @@ discard block |
||
998 | 1290 | case 'BPCHAR': |
999 | 1291 | case '_VARCHAR': |
1000 | 1292 | case 'INET': |
1001 | - if ($len <= $this->blobSize) return 'C'; |
|
1293 | + if ($len <= $this->blobSize) |
|
1294 | + { |
|
1295 | + return 'C'; |
|
1296 | + } |
|
1002 | 1297 | |
1003 | 1298 | case 'TEXT': |
1004 | 1299 | return 'X'; |
@@ -1030,7 +1325,10 @@ discard block |
||
1030 | 1325 | case 'INT4': |
1031 | 1326 | case 'INT2': |
1032 | 1327 | if (isset($fieldobj) && |
1033 | - empty($fieldobj->primary_key) && empty($fieldobj->unique)) return 'I'; |
|
1328 | + empty($fieldobj->primary_key) && empty($fieldobj->unique)) |
|
1329 | + { |
|
1330 | + return 'I'; |
|
1331 | + } |
|
1034 | 1332 | |
1035 | 1333 | case 'OID': |
1036 | 1334 | case 'SERIAL': |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | return $ret; |
179 | 179 | } |
180 | 180 | // to really return the id, we need the table and column-name, else we can only return the oid != id |
181 | - return empty($table) || empty($column) ? $oid : $this->GetOne("SELECT $column FROM $table WHERE oid=".(int)$oid); |
|
181 | + return empty($table) || empty($column) ? $oid : $this->GetOne("select $column FROM $table WHERE oid=".(int)$oid); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | // I get this error with PHP before 4.0.6 - jlim |
@@ -443,10 +443,10 @@ discard block |
||
443 | 443 | { |
444 | 444 | |
445 | 445 | if ($blobtype == 'CLOB') { |
446 | - return $this->Execute("UPDATE $table SET $column=" . $this->qstr($val) . " WHERE $where"); |
|
446 | + return $this->Execute("update $table SET $column=" . $this->qstr($val) . " WHERE $where"); |
|
447 | 447 | } |
448 | 448 | // do not use bind params which uses qstr(), as blobencode() already quotes data |
449 | - return $this->Execute("UPDATE $table SET $column='".$this->BlobEncode($val)."'::bytea WHERE $where"); |
|
449 | + return $this->Execute("update $table SET $column='".$this->BlobEncode($val)."'::bytea WHERE $where"); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | function OffsetDate($dayFraction,$date=false) |
@@ -552,9 +552,9 @@ discard block |
||
552 | 552 | // Freek |
553 | 553 | if (is_array($keys)) { |
554 | 554 | foreach($keys as $key) { |
555 | - if ($fld->name == $key['column_name'] AND $key['primary_key'] == 't') |
|
555 | + if ($fld->name == $key['column_name'] and $key['primary_key'] == 't') |
|
556 | 556 | $fld->primary_key = true; |
557 | - if ($fld->name == $key['column_name'] AND $key['unique_key'] == 't') |
|
557 | + if ($fld->name == $key['column_name'] and $key['unique_key'] == 't') |
|
558 | 558 | $fld->unique = true; // What name is more compatible? |
559 | 559 | } |
560 | 560 | } |
@@ -731,8 +731,8 @@ discard block |
||
731 | 731 | } |
732 | 732 | } |
733 | 733 | |
734 | - if ($execp) $exsql = "EXECUTE $plan ($execp)"; |
|
735 | - else $exsql = "EXECUTE $plan"; |
|
734 | + if ($execp) $exsql = "execute $plan ($execp)"; |
|
735 | + else $exsql = "execute $plan"; |
|
736 | 736 | |
737 | 737 | $rez = @pg_exec($this->_connectionID,$exsql); |
738 | 738 | if (!$rez) { |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | $sql .= $v.' $'.$i; |
757 | 757 | $i++; |
758 | 758 | } |
759 | - $s = "PREPARE $plan ($params) AS ".substr($sql,0,strlen($sql)-2); |
|
759 | + $s = "prepare $plan ($params) AS ".substr($sql,0,strlen($sql)-2); |
|
760 | 760 | //adodb_pr($s); |
761 | 761 | pg_exec($this->_connectionID,$s); |
762 | 762 | echo $this->ErrorMsg(); |
@@ -65,11 +65,17 @@ discard block |
||
65 | 65 | return $this->GetOne('select @@identity'); |
66 | 66 | } |
67 | 67 | |
68 | + /** |
|
69 | + * @param string $blobVarName |
|
70 | + */ |
|
68 | 71 | function create_blobvar($blobVarName) { |
69 | 72 | $this->Execute("create variable $blobVarName long binary"); |
70 | 73 | return; |
71 | 74 | } |
72 | 75 | |
76 | + /** |
|
77 | + * @param string $blobVarName |
|
78 | + */ |
|
73 | 79 | function drop_blobvar($blobVarName) { |
74 | 80 | $this->Execute("drop variable $blobVarName"); |
75 | 81 | return; |
@@ -105,6 +111,9 @@ discard block |
||
105 | 111 | return; |
106 | 112 | } |
107 | 113 | |
114 | + /** |
|
115 | + * @param string $blobVarName |
|
116 | + */ |
|
108 | 117 | function load_blobvar_from_var($blobVarName, &$varName) { |
109 | 118 | $chunk_size = 1000; |
110 | 119 |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); |
49 | 49 | } |
50 | 50 | |
51 | -if (!defined('ADODB_SYBASE_SQLANYWHERE')){ |
|
51 | +if (!defined('ADODB_SYBASE_SQLANYWHERE')) { |
|
52 | 52 | |
53 | - define('ADODB_SYBASE_SQLANYWHERE',1); |
|
53 | + define('ADODB_SYBASE_SQLANYWHERE', 1); |
|
54 | 54 | |
55 | 55 | class ADODB_sqlanywhere extends ADODB_odbc { |
56 | 56 | var $databaseType = "sqlanywhere"; |
@@ -78,30 +78,30 @@ discard block |
||
78 | 78 | function load_blobvar_from_file($blobVarName, $filename) { |
79 | 79 | $chunk_size = 1000; |
80 | 80 | |
81 | - $fd = fopen ($filename, "rb"); |
|
81 | + $fd = fopen($filename, "rb"); |
|
82 | 82 | |
83 | 83 | $integer_chunks = (integer)filesize($filename) / $chunk_size; |
84 | 84 | $modulus = filesize($filename) % $chunk_size; |
85 | - if ($modulus != 0){ |
|
85 | + if ($modulus != 0) { |
|
86 | 86 | $integer_chunks += 1; |
87 | 87 | } |
88 | 88 | |
89 | - for($loop=1;$loop<=$integer_chunks;$loop++){ |
|
90 | - $contents = fread ($fd, $chunk_size); |
|
89 | + for ($loop = 1; $loop <= $integer_chunks; $loop++) { |
|
90 | + $contents = fread($fd, $chunk_size); |
|
91 | 91 | $contents = bin2hex($contents); |
92 | 92 | |
93 | 93 | $hexstring = ''; |
94 | 94 | |
95 | - for($loop2=0;$loop2<strlen($contents);$loop2+=2){ |
|
96 | - $hexstring .= '\x' . substr($contents,$loop2,2); |
|
95 | + for ($loop2 = 0; $loop2 < strlen($contents); $loop2 += 2) { |
|
96 | + $hexstring .= '\x'.substr($contents, $loop2, 2); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | $hexstring = $this->qstr($hexstring); |
100 | 100 | |
101 | - $this->Execute("set $blobVarName = $blobVarName || " . $hexstring); |
|
101 | + $this->Execute("set $blobVarName = $blobVarName || ".$hexstring); |
|
102 | 102 | } |
103 | 103 | |
104 | - fclose ($fd); |
|
104 | + fclose($fd); |
|
105 | 105 | return; |
106 | 106 | } |
107 | 107 | |
@@ -110,23 +110,23 @@ discard block |
||
110 | 110 | |
111 | 111 | $integer_chunks = (integer)strlen($varName) / $chunk_size; |
112 | 112 | $modulus = strlen($varName) % $chunk_size; |
113 | - if ($modulus != 0){ |
|
113 | + if ($modulus != 0) { |
|
114 | 114 | $integer_chunks += 1; |
115 | 115 | } |
116 | 116 | |
117 | - for($loop=1;$loop<=$integer_chunks;$loop++){ |
|
118 | - $contents = substr ($varName, (($loop - 1) * $chunk_size), $chunk_size); |
|
117 | + for ($loop = 1; $loop <= $integer_chunks; $loop++) { |
|
118 | + $contents = substr($varName, (($loop - 1) * $chunk_size), $chunk_size); |
|
119 | 119 | $contents = bin2hex($contents); |
120 | 120 | |
121 | 121 | $hexstring = ''; |
122 | 122 | |
123 | - for($loop2=0;$loop2<strlen($contents);$loop2+=2){ |
|
124 | - $hexstring .= '\x' . substr($contents,$loop2,2); |
|
123 | + for ($loop2 = 0; $loop2 < strlen($contents); $loop2 += 2) { |
|
124 | + $hexstring .= '\x'.substr($contents, $loop2, 2); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | $hexstring = $this->qstr($hexstring); |
128 | 128 | |
129 | - $this->Execute("set $blobVarName = $blobVarName || " . $hexstring); |
|
129 | + $this->Execute("set $blobVarName = $blobVarName || ".$hexstring); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | return; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); |
142 | 142 | $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); |
143 | 143 | */ |
144 | - function UpdateBlob($table,$column,&$val,$where,$blobtype='BLOB') |
|
144 | + function UpdateBlob($table, $column, &$val, $where, $blobtype = 'BLOB') |
|
145 | 145 | { |
146 | 146 | $blobVarName = 'hold_blob'; |
147 | 147 | $this->create_blobvar($blobVarName); |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | |
157 | 157 | var $databaseType = "sqlanywhere"; |
158 | 158 | |
159 | - function ADORecordSet_sqlanywhere($id,$mode=false) |
|
159 | + function ADORecordSet_sqlanywhere($id, $mode = false) |
|
160 | 160 | { |
161 | - $this->ADORecordSet_odbc($id,$mode); |
|
161 | + $this->ADORecordSet_odbc($id, $mode); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 |
@@ -42,17 +42,23 @@ discard block |
||
42 | 42 | */ |
43 | 43 | |
44 | 44 | // security - hide paths |
45 | -if (!defined('ADODB_DIR')) die(); |
|
45 | +if (!defined('ADODB_DIR')) |
|
46 | +{ |
|
47 | + die(); |
|
48 | +} |
|
46 | 49 | |
47 | -if (!defined('_ADODB_ODBC_LAYER')) { |
|
50 | +if (!defined('_ADODB_ODBC_LAYER')) |
|
51 | +{ |
|
48 | 52 | include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); |
49 | 53 | } |
50 | 54 | |
51 | -if (!defined('ADODB_SYBASE_SQLANYWHERE')){ |
|
55 | +if (!defined('ADODB_SYBASE_SQLANYWHERE')) |
|
56 | +{ |
|
52 | 57 | |
53 | 58 | define('ADODB_SYBASE_SQLANYWHERE',1); |
54 | 59 | |
55 | - class ADODB_sqlanywhere extends ADODB_odbc { |
|
60 | + class ADODB_sqlanywhere extends ADODB_odbc |
|
61 | + { |
|
56 | 62 | var $databaseType = "sqlanywhere"; |
57 | 63 | var $hasInsertID = true; |
58 | 64 | |
@@ -61,38 +67,45 @@ discard block |
||
61 | 67 | $this->ADODB_odbc(); |
62 | 68 | } |
63 | 69 | |
64 | - function _insertid() { |
|
70 | + function _insertid() |
|
71 | + { |
|
65 | 72 | return $this->GetOne('select @@identity'); |
66 | 73 | } |
67 | 74 | |
68 | - function create_blobvar($blobVarName) { |
|
75 | + function create_blobvar($blobVarName) |
|
76 | + { |
|
69 | 77 | $this->Execute("create variable $blobVarName long binary"); |
70 | 78 | return; |
71 | 79 | } |
72 | 80 | |
73 | - function drop_blobvar($blobVarName) { |
|
81 | + function drop_blobvar($blobVarName) |
|
82 | + { |
|
74 | 83 | $this->Execute("drop variable $blobVarName"); |
75 | 84 | return; |
76 | 85 | } |
77 | 86 | |
78 | - function load_blobvar_from_file($blobVarName, $filename) { |
|
87 | + function load_blobvar_from_file($blobVarName, $filename) |
|
88 | + { |
|
79 | 89 | $chunk_size = 1000; |
80 | 90 | |
81 | 91 | $fd = fopen ($filename, "rb"); |
82 | 92 | |
83 | 93 | $integer_chunks = (integer)filesize($filename) / $chunk_size; |
84 | 94 | $modulus = filesize($filename) % $chunk_size; |
85 | - if ($modulus != 0){ |
|
95 | + if ($modulus != 0) |
|
96 | + { |
|
86 | 97 | $integer_chunks += 1; |
87 | 98 | } |
88 | 99 | |
89 | - for($loop=1;$loop<=$integer_chunks;$loop++){ |
|
100 | + for($loop=1;$loop<=$integer_chunks;$loop++) |
|
101 | + { |
|
90 | 102 | $contents = fread ($fd, $chunk_size); |
91 | 103 | $contents = bin2hex($contents); |
92 | 104 | |
93 | 105 | $hexstring = ''; |
94 | 106 | |
95 | - for($loop2=0;$loop2<strlen($contents);$loop2+=2){ |
|
107 | + for($loop2=0;$loop2<strlen($contents);$loop2+=2) |
|
108 | + { |
|
96 | 109 | $hexstring .= '\x' . substr($contents,$loop2,2); |
97 | 110 | } |
98 | 111 | |
@@ -105,22 +118,26 @@ discard block |
||
105 | 118 | return; |
106 | 119 | } |
107 | 120 | |
108 | - function load_blobvar_from_var($blobVarName, &$varName) { |
|
121 | + function load_blobvar_from_var($blobVarName, &$varName) |
|
122 | + { |
|
109 | 123 | $chunk_size = 1000; |
110 | 124 | |
111 | 125 | $integer_chunks = (integer)strlen($varName) / $chunk_size; |
112 | 126 | $modulus = strlen($varName) % $chunk_size; |
113 | - if ($modulus != 0){ |
|
127 | + if ($modulus != 0) |
|
128 | + { |
|
114 | 129 | $integer_chunks += 1; |
115 | 130 | } |
116 | 131 | |
117 | - for($loop=1;$loop<=$integer_chunks;$loop++){ |
|
132 | + for($loop=1;$loop<=$integer_chunks;$loop++) |
|
133 | + { |
|
118 | 134 | $contents = substr ($varName, (($loop - 1) * $chunk_size), $chunk_size); |
119 | 135 | $contents = bin2hex($contents); |
120 | 136 | |
121 | 137 | $hexstring = ''; |
122 | 138 | |
123 | - for($loop2=0;$loop2<strlen($contents);$loop2+=2){ |
|
139 | + for($loop2=0;$loop2<strlen($contents);$loop2+=2) |
|
140 | + { |
|
124 | 141 | $hexstring .= '\x' . substr($contents,$loop2,2); |
125 | 142 | } |
126 | 143 | |
@@ -152,7 +169,8 @@ discard block |
||
152 | 169 | } |
153 | 170 | }; //class |
154 | 171 | |
155 | - class ADORecordSet_sqlanywhere extends ADORecordSet_odbc { |
|
172 | + class ADORecordSet_sqlanywhere extends ADORecordSet_odbc |
|
173 | + { |
|
156 | 174 | |
157 | 175 | var $databaseType = "sqlanywhere"; |
158 | 176 |
@@ -146,7 +146,7 @@ |
||
146 | 146 | $blobVarName = 'hold_blob'; |
147 | 147 | $this->create_blobvar($blobVarName); |
148 | 148 | $this->load_blobvar_from_var($blobVarName, $val); |
149 | - $this->Execute("UPDATE $table SET $column=$blobVarName WHERE $where"); |
|
149 | + $this->Execute("update $table SET $column=$blobVarName WHERE $where"); |
|
150 | 150 | $this->drop_blobvar($blobVarName); |
151 | 151 | return true; |
152 | 152 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * the database. If that's not the case, a new connection is opened. |
132 | 132 | * |
133 | 133 | * @access private |
134 | - * @return mixed True or a DB error object. |
|
134 | + * @return boolean True or a DB error object. |
|
135 | 135 | */ |
136 | 136 | function _prepare() |
137 | 137 | { |
@@ -153,6 +153,7 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @access public |
155 | 155 | * @param string Query string |
156 | + * @param string $query |
|
156 | 157 | * @return mixed a DB_result object or DB_OK on success, a DB |
157 | 158 | * or PEAR error on failure |
158 | 159 | */ |
@@ -40,365 +40,365 @@ |
||
40 | 40 | class Auth_Container_ADOdb extends Auth_Container |
41 | 41 | { |
42 | 42 | |
43 | - /** |
|
44 | - * Additional options for the storage container |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - var $options = array(); |
|
48 | - |
|
49 | - /** |
|
50 | - * DB object |
|
51 | - * @var object |
|
52 | - */ |
|
53 | - var $db = null; |
|
54 | - var $dsn = ''; |
|
43 | + /** |
|
44 | + * Additional options for the storage container |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + var $options = array(); |
|
48 | + |
|
49 | + /** |
|
50 | + * DB object |
|
51 | + * @var object |
|
52 | + */ |
|
53 | + var $db = null; |
|
54 | + var $dsn = ''; |
|
55 | 55 | |
56 | - /** |
|
57 | - * User that is currently selected from the DB. |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - var $activeUser = ''; |
|
61 | - |
|
62 | - // {{{ Constructor |
|
63 | - |
|
64 | - /** |
|
65 | - * Constructor of the container class |
|
66 | - * |
|
67 | - * Initate connection to the database via PEAR::ADOdb |
|
68 | - * |
|
69 | - * @param string Connection data or DB object |
|
70 | - * @return object Returns an error object if something went wrong |
|
71 | - */ |
|
72 | - function Auth_Container_ADOdb($dsn) |
|
73 | - { |
|
74 | - $this->_setDefaults(); |
|
56 | + /** |
|
57 | + * User that is currently selected from the DB. |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + var $activeUser = ''; |
|
61 | + |
|
62 | + // {{{ Constructor |
|
63 | + |
|
64 | + /** |
|
65 | + * Constructor of the container class |
|
66 | + * |
|
67 | + * Initate connection to the database via PEAR::ADOdb |
|
68 | + * |
|
69 | + * @param string Connection data or DB object |
|
70 | + * @return object Returns an error object if something went wrong |
|
71 | + */ |
|
72 | + function Auth_Container_ADOdb($dsn) |
|
73 | + { |
|
74 | + $this->_setDefaults(); |
|
75 | 75 | |
76 | - if (is_array($dsn)) { |
|
77 | - $this->_parseOptions($dsn); |
|
78 | - |
|
79 | - if (empty($this->options['dsn'])) { |
|
80 | - PEAR::raiseError('No connection parameters specified!'); |
|
81 | - } |
|
82 | - } else { |
|
83 | - // Extract db_type from dsn string. |
|
84 | - $this->options['dsn'] = $dsn; |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - // }}} |
|
89 | - // {{{ _connect() |
|
90 | - |
|
91 | - /** |
|
92 | - * Connect to database by using the given DSN string |
|
93 | - * |
|
94 | - * @access private |
|
95 | - * @param string DSN string |
|
96 | - * @return mixed Object on error, otherwise bool |
|
97 | - */ |
|
98 | - function _connect($dsn) |
|
99 | - { |
|
100 | - if (is_string($dsn) || is_array($dsn)) { |
|
101 | - if(!$this->db) { |
|
102 | - $this->db = &ADONewConnection($dsn); |
|
103 | - if( $err = ADODB_Pear_error() ) { |
|
104 | - return PEAR::raiseError($err); |
|
105 | - } |
|
106 | - } |
|
76 | + if (is_array($dsn)) { |
|
77 | + $this->_parseOptions($dsn); |
|
78 | + |
|
79 | + if (empty($this->options['dsn'])) { |
|
80 | + PEAR::raiseError('No connection parameters specified!'); |
|
81 | + } |
|
82 | + } else { |
|
83 | + // Extract db_type from dsn string. |
|
84 | + $this->options['dsn'] = $dsn; |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + // }}} |
|
89 | + // {{{ _connect() |
|
90 | + |
|
91 | + /** |
|
92 | + * Connect to database by using the given DSN string |
|
93 | + * |
|
94 | + * @access private |
|
95 | + * @param string DSN string |
|
96 | + * @return mixed Object on error, otherwise bool |
|
97 | + */ |
|
98 | + function _connect($dsn) |
|
99 | + { |
|
100 | + if (is_string($dsn) || is_array($dsn)) { |
|
101 | + if(!$this->db) { |
|
102 | + $this->db = &ADONewConnection($dsn); |
|
103 | + if( $err = ADODB_Pear_error() ) { |
|
104 | + return PEAR::raiseError($err); |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - } else { |
|
109 | - return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__, |
|
110 | - 41, |
|
111 | - PEAR_ERROR_RETURN, |
|
112 | - null, |
|
113 | - null |
|
114 | - ); |
|
115 | - } |
|
108 | + } else { |
|
109 | + return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__, |
|
110 | + 41, |
|
111 | + PEAR_ERROR_RETURN, |
|
112 | + null, |
|
113 | + null |
|
114 | + ); |
|
115 | + } |
|
116 | 116 | |
117 | - if(!$this->db) { |
|
118 | - return PEAR::raiseError(ADODB_Pear_error()); |
|
119 | - } else { |
|
120 | - return true; |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - // }}} |
|
125 | - // {{{ _prepare() |
|
126 | - |
|
127 | - /** |
|
128 | - * Prepare database connection |
|
129 | - * |
|
130 | - * This function checks if we have already opened a connection to |
|
131 | - * the database. If that's not the case, a new connection is opened. |
|
132 | - * |
|
133 | - * @access private |
|
134 | - * @return mixed True or a DB error object. |
|
135 | - */ |
|
136 | - function _prepare() |
|
137 | - { |
|
138 | - if(!$this->db) { |
|
139 | - $res = $this->_connect($this->options['dsn']); |
|
140 | - } |
|
141 | - return true; |
|
142 | - } |
|
143 | - |
|
144 | - // }}} |
|
145 | - // {{{ query() |
|
146 | - |
|
147 | - /** |
|
148 | - * Prepare query to the database |
|
149 | - * |
|
150 | - * This function checks if we have already opened a connection to |
|
151 | - * the database. If that's not the case, a new connection is opened. |
|
152 | - * After that the query is passed to the database. |
|
153 | - * |
|
154 | - * @access public |
|
155 | - * @param string Query string |
|
156 | - * @return mixed a DB_result object or DB_OK on success, a DB |
|
157 | - * or PEAR error on failure |
|
158 | - */ |
|
159 | - function query($query) |
|
160 | - { |
|
161 | - $err = $this->_prepare(); |
|
162 | - if ($err !== true) { |
|
163 | - return $err; |
|
164 | - } |
|
165 | - return $this->db->query($query); |
|
166 | - } |
|
167 | - |
|
168 | - // }}} |
|
169 | - // {{{ _setDefaults() |
|
170 | - |
|
171 | - /** |
|
172 | - * Set some default options |
|
173 | - * |
|
174 | - * @access private |
|
175 | - * @return void |
|
176 | - */ |
|
177 | - function _setDefaults() |
|
178 | - { |
|
179 | - $this->options['db_type'] = 'mysql'; |
|
180 | - $this->options['table'] = 'auth'; |
|
181 | - $this->options['usernamecol'] = 'username'; |
|
182 | - $this->options['passwordcol'] = 'password'; |
|
183 | - $this->options['dsn'] = ''; |
|
184 | - $this->options['db_fields'] = ''; |
|
185 | - $this->options['cryptType'] = 'md5'; |
|
186 | - } |
|
187 | - |
|
188 | - // }}} |
|
189 | - // {{{ _parseOptions() |
|
190 | - |
|
191 | - /** |
|
192 | - * Parse options passed to the container class |
|
193 | - * |
|
194 | - * @access private |
|
195 | - * @param array |
|
196 | - */ |
|
197 | - function _parseOptions($array) |
|
198 | - { |
|
199 | - foreach ($array as $key => $value) { |
|
200 | - if (isset($this->options[$key])) { |
|
201 | - $this->options[$key] = $value; |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - /* Include additional fields if they exist */ |
|
206 | - if(!empty($this->options['db_fields'])){ |
|
207 | - if(is_array($this->options['db_fields'])){ |
|
208 | - $this->options['db_fields'] = join($this->options['db_fields'], ', '); |
|
209 | - } |
|
210 | - $this->options['db_fields'] = ', '.$this->options['db_fields']; |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - // }}} |
|
215 | - // {{{ fetchData() |
|
216 | - |
|
217 | - /** |
|
218 | - * Get user information from database |
|
219 | - * |
|
220 | - * This function uses the given username to fetch |
|
221 | - * the corresponding login data from the database |
|
222 | - * table. If an account that matches the passed username |
|
223 | - * and password is found, the function returns true. |
|
224 | - * Otherwise it returns false. |
|
225 | - * |
|
226 | - * @param string Username |
|
227 | - * @param string Password |
|
228 | - * @return mixed Error object or boolean |
|
229 | - */ |
|
230 | - function fetchData($username, $password) |
|
231 | - { |
|
232 | - // Prepare for a database query |
|
233 | - $err = $this->_prepare(); |
|
234 | - if ($err !== true) { |
|
235 | - return PEAR::raiseError($err->getMessage(), $err->getCode()); |
|
236 | - } |
|
237 | - |
|
238 | - // Find if db_fields contains a *, i so assume all col are selected |
|
239 | - if(strstr($this->options['db_fields'], '*')){ |
|
240 | - $sql_from = "*"; |
|
241 | - } |
|
242 | - else{ |
|
243 | - $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
244 | - } |
|
117 | + if(!$this->db) { |
|
118 | + return PEAR::raiseError(ADODB_Pear_error()); |
|
119 | + } else { |
|
120 | + return true; |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + // }}} |
|
125 | + // {{{ _prepare() |
|
126 | + |
|
127 | + /** |
|
128 | + * Prepare database connection |
|
129 | + * |
|
130 | + * This function checks if we have already opened a connection to |
|
131 | + * the database. If that's not the case, a new connection is opened. |
|
132 | + * |
|
133 | + * @access private |
|
134 | + * @return mixed True or a DB error object. |
|
135 | + */ |
|
136 | + function _prepare() |
|
137 | + { |
|
138 | + if(!$this->db) { |
|
139 | + $res = $this->_connect($this->options['dsn']); |
|
140 | + } |
|
141 | + return true; |
|
142 | + } |
|
143 | + |
|
144 | + // }}} |
|
145 | + // {{{ query() |
|
146 | + |
|
147 | + /** |
|
148 | + * Prepare query to the database |
|
149 | + * |
|
150 | + * This function checks if we have already opened a connection to |
|
151 | + * the database. If that's not the case, a new connection is opened. |
|
152 | + * After that the query is passed to the database. |
|
153 | + * |
|
154 | + * @access public |
|
155 | + * @param string Query string |
|
156 | + * @return mixed a DB_result object or DB_OK on success, a DB |
|
157 | + * or PEAR error on failure |
|
158 | + */ |
|
159 | + function query($query) |
|
160 | + { |
|
161 | + $err = $this->_prepare(); |
|
162 | + if ($err !== true) { |
|
163 | + return $err; |
|
164 | + } |
|
165 | + return $this->db->query($query); |
|
166 | + } |
|
167 | + |
|
168 | + // }}} |
|
169 | + // {{{ _setDefaults() |
|
170 | + |
|
171 | + /** |
|
172 | + * Set some default options |
|
173 | + * |
|
174 | + * @access private |
|
175 | + * @return void |
|
176 | + */ |
|
177 | + function _setDefaults() |
|
178 | + { |
|
179 | + $this->options['db_type'] = 'mysql'; |
|
180 | + $this->options['table'] = 'auth'; |
|
181 | + $this->options['usernamecol'] = 'username'; |
|
182 | + $this->options['passwordcol'] = 'password'; |
|
183 | + $this->options['dsn'] = ''; |
|
184 | + $this->options['db_fields'] = ''; |
|
185 | + $this->options['cryptType'] = 'md5'; |
|
186 | + } |
|
187 | + |
|
188 | + // }}} |
|
189 | + // {{{ _parseOptions() |
|
190 | + |
|
191 | + /** |
|
192 | + * Parse options passed to the container class |
|
193 | + * |
|
194 | + * @access private |
|
195 | + * @param array |
|
196 | + */ |
|
197 | + function _parseOptions($array) |
|
198 | + { |
|
199 | + foreach ($array as $key => $value) { |
|
200 | + if (isset($this->options[$key])) { |
|
201 | + $this->options[$key] = $value; |
|
202 | + } |
|
203 | + } |
|
204 | + |
|
205 | + /* Include additional fields if they exist */ |
|
206 | + if(!empty($this->options['db_fields'])){ |
|
207 | + if(is_array($this->options['db_fields'])){ |
|
208 | + $this->options['db_fields'] = join($this->options['db_fields'], ', '); |
|
209 | + } |
|
210 | + $this->options['db_fields'] = ', '.$this->options['db_fields']; |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + // }}} |
|
215 | + // {{{ fetchData() |
|
216 | + |
|
217 | + /** |
|
218 | + * Get user information from database |
|
219 | + * |
|
220 | + * This function uses the given username to fetch |
|
221 | + * the corresponding login data from the database |
|
222 | + * table. If an account that matches the passed username |
|
223 | + * and password is found, the function returns true. |
|
224 | + * Otherwise it returns false. |
|
225 | + * |
|
226 | + * @param string Username |
|
227 | + * @param string Password |
|
228 | + * @return mixed Error object or boolean |
|
229 | + */ |
|
230 | + function fetchData($username, $password) |
|
231 | + { |
|
232 | + // Prepare for a database query |
|
233 | + $err = $this->_prepare(); |
|
234 | + if ($err !== true) { |
|
235 | + return PEAR::raiseError($err->getMessage(), $err->getCode()); |
|
236 | + } |
|
237 | + |
|
238 | + // Find if db_fields contains a *, i so assume all col are selected |
|
239 | + if(strstr($this->options['db_fields'], '*')){ |
|
240 | + $sql_from = "*"; |
|
241 | + } |
|
242 | + else{ |
|
243 | + $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
244 | + } |
|
245 | 245 | |
246 | - $query = "SELECT ".$sql_from. |
|
247 | - " FROM ".$this->options['table']. |
|
248 | - " WHERE ".$this->options['usernamecol']." = " . $this->db->Quote($username); |
|
246 | + $query = "SELECT ".$sql_from. |
|
247 | + " FROM ".$this->options['table']. |
|
248 | + " WHERE ".$this->options['usernamecol']." = " . $this->db->Quote($username); |
|
249 | 249 | |
250 | - $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|
251 | - $rset = $this->db->Execute( $query ); |
|
252 | - $res = $rset->fetchRow(); |
|
253 | - |
|
254 | - if (DB::isError($res)) { |
|
255 | - return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
256 | - } |
|
257 | - if (!is_array($res)) { |
|
258 | - $this->activeUser = ''; |
|
259 | - return false; |
|
260 | - } |
|
261 | - if ($this->verifyPassword(trim($password, "\r\n"), |
|
262 | - trim($res[$this->options['passwordcol']], "\r\n"), |
|
263 | - $this->options['cryptType'])) { |
|
264 | - // Store additional field values in the session |
|
265 | - foreach ($res as $key => $value) { |
|
266 | - if ($key == $this->options['passwordcol'] || |
|
267 | - $key == $this->options['usernamecol']) { |
|
268 | - continue; |
|
269 | - } |
|
270 | - // Use reference to the auth object if exists |
|
271 | - // This is because the auth session variable can change so a static call to setAuthData does not make sence |
|
272 | - if(is_object($this->_auth_obj)){ |
|
273 | - $this->_auth_obj->setAuthData($key, $value); |
|
274 | - } else { |
|
275 | - Auth::setAuthData($key, $value); |
|
276 | - } |
|
277 | - } |
|
278 | - |
|
279 | - return true; |
|
280 | - } |
|
281 | - |
|
282 | - $this->activeUser = $res[$this->options['usernamecol']]; |
|
283 | - return false; |
|
284 | - } |
|
285 | - |
|
286 | - // }}} |
|
287 | - // {{{ listUsers() |
|
288 | - |
|
289 | - function listUsers() |
|
290 | - { |
|
291 | - $err = $this->_prepare(); |
|
292 | - if ($err !== true) { |
|
293 | - return PEAR::raiseError($err->getMessage(), $err->getCode()); |
|
294 | - } |
|
295 | - |
|
296 | - $retVal = array(); |
|
297 | - |
|
298 | - // Find if db_fileds contains a *, i so assume all col are selected |
|
299 | - if(strstr($this->options['db_fields'], '*')){ |
|
300 | - $sql_from = "*"; |
|
301 | - } |
|
302 | - else{ |
|
303 | - $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
304 | - } |
|
305 | - |
|
306 | - $query = sprintf("SELECT %s FROM %s", |
|
307 | - $sql_from, |
|
308 | - $this->options['table'] |
|
309 | - ); |
|
310 | - $res = $this->db->getAll($query, null, DB_FETCHMODE_ASSOC); |
|
311 | - |
|
312 | - if (DB::isError($res)) { |
|
313 | - return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
314 | - } else { |
|
315 | - foreach ($res as $user) { |
|
316 | - $user['username'] = $user[$this->options['usernamecol']]; |
|
317 | - $retVal[] = $user; |
|
318 | - } |
|
319 | - } |
|
320 | - return $retVal; |
|
321 | - } |
|
322 | - |
|
323 | - // }}} |
|
324 | - // {{{ addUser() |
|
325 | - |
|
326 | - /** |
|
327 | - * Add user to the storage container |
|
328 | - * |
|
329 | - * @access public |
|
330 | - * @param string Username |
|
331 | - * @param string Password |
|
332 | - * @param mixed Additional information that are stored in the DB |
|
333 | - * |
|
334 | - * @return mixed True on success, otherwise error object |
|
335 | - */ |
|
336 | - function addUser($username, $password, $additional = "") |
|
337 | - { |
|
338 | - if (function_exists($this->options['cryptType'])) { |
|
339 | - $cryptFunction = $this->options['cryptType']; |
|
340 | - } else { |
|
341 | - $cryptFunction = 'md5'; |
|
342 | - } |
|
343 | - |
|
344 | - $additional_key = ''; |
|
345 | - $additional_value = ''; |
|
346 | - |
|
347 | - if (is_array($additional)) { |
|
348 | - foreach ($additional as $key => $value) { |
|
349 | - $additional_key .= ', ' . $key; |
|
350 | - $additional_value .= ", '" . $value . "'"; |
|
351 | - } |
|
352 | - } |
|
353 | - |
|
354 | - $query = sprintf("INSERT INTO %s (%s, %s%s) VALUES ('%s', '%s'%s)", |
|
355 | - $this->options['table'], |
|
356 | - $this->options['usernamecol'], |
|
357 | - $this->options['passwordcol'], |
|
358 | - $additional_key, |
|
359 | - $username, |
|
360 | - $cryptFunction($password), |
|
361 | - $additional_value |
|
362 | - ); |
|
363 | - |
|
364 | - $res = $this->query($query); |
|
365 | - |
|
366 | - if (DB::isError($res)) { |
|
367 | - return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
368 | - } else { |
|
369 | - return true; |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - // }}} |
|
374 | - // {{{ removeUser() |
|
375 | - |
|
376 | - /** |
|
377 | - * Remove user from the storage container |
|
378 | - * |
|
379 | - * @access public |
|
380 | - * @param string Username |
|
381 | - * |
|
382 | - * @return mixed True on success, otherwise error object |
|
383 | - */ |
|
384 | - function removeUser($username) |
|
385 | - { |
|
386 | - $query = sprintf("DELETE FROM %s WHERE %s = '%s'", |
|
387 | - $this->options['table'], |
|
388 | - $this->options['usernamecol'], |
|
389 | - $username |
|
390 | - ); |
|
391 | - |
|
392 | - $res = $this->query($query); |
|
393 | - |
|
394 | - if (DB::isError($res)) { |
|
395 | - return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
396 | - } else { |
|
397 | - return true; |
|
398 | - } |
|
399 | - } |
|
400 | - |
|
401 | - // }}} |
|
250 | + $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|
251 | + $rset = $this->db->Execute( $query ); |
|
252 | + $res = $rset->fetchRow(); |
|
253 | + |
|
254 | + if (DB::isError($res)) { |
|
255 | + return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
256 | + } |
|
257 | + if (!is_array($res)) { |
|
258 | + $this->activeUser = ''; |
|
259 | + return false; |
|
260 | + } |
|
261 | + if ($this->verifyPassword(trim($password, "\r\n"), |
|
262 | + trim($res[$this->options['passwordcol']], "\r\n"), |
|
263 | + $this->options['cryptType'])) { |
|
264 | + // Store additional field values in the session |
|
265 | + foreach ($res as $key => $value) { |
|
266 | + if ($key == $this->options['passwordcol'] || |
|
267 | + $key == $this->options['usernamecol']) { |
|
268 | + continue; |
|
269 | + } |
|
270 | + // Use reference to the auth object if exists |
|
271 | + // This is because the auth session variable can change so a static call to setAuthData does not make sence |
|
272 | + if(is_object($this->_auth_obj)){ |
|
273 | + $this->_auth_obj->setAuthData($key, $value); |
|
274 | + } else { |
|
275 | + Auth::setAuthData($key, $value); |
|
276 | + } |
|
277 | + } |
|
278 | + |
|
279 | + return true; |
|
280 | + } |
|
281 | + |
|
282 | + $this->activeUser = $res[$this->options['usernamecol']]; |
|
283 | + return false; |
|
284 | + } |
|
285 | + |
|
286 | + // }}} |
|
287 | + // {{{ listUsers() |
|
288 | + |
|
289 | + function listUsers() |
|
290 | + { |
|
291 | + $err = $this->_prepare(); |
|
292 | + if ($err !== true) { |
|
293 | + return PEAR::raiseError($err->getMessage(), $err->getCode()); |
|
294 | + } |
|
295 | + |
|
296 | + $retVal = array(); |
|
297 | + |
|
298 | + // Find if db_fileds contains a *, i so assume all col are selected |
|
299 | + if(strstr($this->options['db_fields'], '*')){ |
|
300 | + $sql_from = "*"; |
|
301 | + } |
|
302 | + else{ |
|
303 | + $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
304 | + } |
|
305 | + |
|
306 | + $query = sprintf("SELECT %s FROM %s", |
|
307 | + $sql_from, |
|
308 | + $this->options['table'] |
|
309 | + ); |
|
310 | + $res = $this->db->getAll($query, null, DB_FETCHMODE_ASSOC); |
|
311 | + |
|
312 | + if (DB::isError($res)) { |
|
313 | + return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
314 | + } else { |
|
315 | + foreach ($res as $user) { |
|
316 | + $user['username'] = $user[$this->options['usernamecol']]; |
|
317 | + $retVal[] = $user; |
|
318 | + } |
|
319 | + } |
|
320 | + return $retVal; |
|
321 | + } |
|
322 | + |
|
323 | + // }}} |
|
324 | + // {{{ addUser() |
|
325 | + |
|
326 | + /** |
|
327 | + * Add user to the storage container |
|
328 | + * |
|
329 | + * @access public |
|
330 | + * @param string Username |
|
331 | + * @param string Password |
|
332 | + * @param mixed Additional information that are stored in the DB |
|
333 | + * |
|
334 | + * @return mixed True on success, otherwise error object |
|
335 | + */ |
|
336 | + function addUser($username, $password, $additional = "") |
|
337 | + { |
|
338 | + if (function_exists($this->options['cryptType'])) { |
|
339 | + $cryptFunction = $this->options['cryptType']; |
|
340 | + } else { |
|
341 | + $cryptFunction = 'md5'; |
|
342 | + } |
|
343 | + |
|
344 | + $additional_key = ''; |
|
345 | + $additional_value = ''; |
|
346 | + |
|
347 | + if (is_array($additional)) { |
|
348 | + foreach ($additional as $key => $value) { |
|
349 | + $additional_key .= ', ' . $key; |
|
350 | + $additional_value .= ", '" . $value . "'"; |
|
351 | + } |
|
352 | + } |
|
353 | + |
|
354 | + $query = sprintf("INSERT INTO %s (%s, %s%s) VALUES ('%s', '%s'%s)", |
|
355 | + $this->options['table'], |
|
356 | + $this->options['usernamecol'], |
|
357 | + $this->options['passwordcol'], |
|
358 | + $additional_key, |
|
359 | + $username, |
|
360 | + $cryptFunction($password), |
|
361 | + $additional_value |
|
362 | + ); |
|
363 | + |
|
364 | + $res = $this->query($query); |
|
365 | + |
|
366 | + if (DB::isError($res)) { |
|
367 | + return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
368 | + } else { |
|
369 | + return true; |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + // }}} |
|
374 | + // {{{ removeUser() |
|
375 | + |
|
376 | + /** |
|
377 | + * Remove user from the storage container |
|
378 | + * |
|
379 | + * @access public |
|
380 | + * @param string Username |
|
381 | + * |
|
382 | + * @return mixed True on success, otherwise error object |
|
383 | + */ |
|
384 | + function removeUser($username) |
|
385 | + { |
|
386 | + $query = sprintf("DELETE FROM %s WHERE %s = '%s'", |
|
387 | + $this->options['table'], |
|
388 | + $this->options['usernamecol'], |
|
389 | + $username |
|
390 | + ); |
|
391 | + |
|
392 | + $res = $this->query($query); |
|
393 | + |
|
394 | + if (DB::isError($res)) { |
|
395 | + return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
396 | + } else { |
|
397 | + return true; |
|
398 | + } |
|
399 | + } |
|
400 | + |
|
401 | + // }}} |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | function showDbg( $string ) { |
@@ -98,15 +98,15 @@ discard block |
||
98 | 98 | function _connect($dsn) |
99 | 99 | { |
100 | 100 | if (is_string($dsn) || is_array($dsn)) { |
101 | - if(!$this->db) { |
|
101 | + if (!$this->db) { |
|
102 | 102 | $this->db = &ADONewConnection($dsn); |
103 | - if( $err = ADODB_Pear_error() ) { |
|
103 | + if ($err = ADODB_Pear_error()) { |
|
104 | 104 | return PEAR::raiseError($err); |
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
108 | 108 | } else { |
109 | - return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__, |
|
109 | + return PEAR::raiseError('The given dsn was not valid in file '.__FILE__.' at line '.__LINE__, |
|
110 | 110 | 41, |
111 | 111 | PEAR_ERROR_RETURN, |
112 | 112 | null, |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | ); |
115 | 115 | } |
116 | 116 | |
117 | - if(!$this->db) { |
|
117 | + if (!$this->db) { |
|
118 | 118 | return PEAR::raiseError(ADODB_Pear_error()); |
119 | 119 | } else { |
120 | 120 | return true; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | function _prepare() |
137 | 137 | { |
138 | - if(!$this->db) { |
|
138 | + if (!$this->db) { |
|
139 | 139 | $res = $this->_connect($this->options['dsn']); |
140 | 140 | } |
141 | 141 | return true; |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | */ |
177 | 177 | function _setDefaults() |
178 | 178 | { |
179 | - $this->options['db_type'] = 'mysql'; |
|
179 | + $this->options['db_type'] = 'mysql'; |
|
180 | 180 | $this->options['table'] = 'auth'; |
181 | 181 | $this->options['usernamecol'] = 'username'; |
182 | 182 | $this->options['passwordcol'] = 'password'; |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | } |
204 | 204 | |
205 | 205 | /* Include additional fields if they exist */ |
206 | - if(!empty($this->options['db_fields'])){ |
|
207 | - if(is_array($this->options['db_fields'])){ |
|
206 | + if (!empty($this->options['db_fields'])) { |
|
207 | + if (is_array($this->options['db_fields'])) { |
|
208 | 208 | $this->options['db_fields'] = join($this->options['db_fields'], ', '); |
209 | 209 | } |
210 | 210 | $this->options['db_fields'] = ', '.$this->options['db_fields']; |
@@ -236,19 +236,19 @@ discard block |
||
236 | 236 | } |
237 | 237 | |
238 | 238 | // Find if db_fields contains a *, i so assume all col are selected |
239 | - if(strstr($this->options['db_fields'], '*')){ |
|
239 | + if (strstr($this->options['db_fields'], '*')) { |
|
240 | 240 | $sql_from = "*"; |
241 | 241 | } |
242 | - else{ |
|
243 | - $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
242 | + else { |
|
243 | + $sql_from = $this->options['usernamecol'].", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | $query = "SELECT ".$sql_from. |
247 | 247 | " FROM ".$this->options['table']. |
248 | - " WHERE ".$this->options['usernamecol']." = " . $this->db->Quote($username); |
|
248 | + " WHERE ".$this->options['usernamecol']." = ".$this->db->Quote($username); |
|
249 | 249 | |
250 | 250 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
251 | - $rset = $this->db->Execute( $query ); |
|
251 | + $rset = $this->db->Execute($query); |
|
252 | 252 | $res = $rset->fetchRow(); |
253 | 253 | |
254 | 254 | if (DB::isError($res)) { |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | } |
270 | 270 | // Use reference to the auth object if exists |
271 | 271 | // This is because the auth session variable can change so a static call to setAuthData does not make sence |
272 | - if(is_object($this->_auth_obj)){ |
|
272 | + if (is_object($this->_auth_obj)) { |
|
273 | 273 | $this->_auth_obj->setAuthData($key, $value); |
274 | 274 | } else { |
275 | 275 | Auth::setAuthData($key, $value); |
@@ -296,11 +296,11 @@ discard block |
||
296 | 296 | $retVal = array(); |
297 | 297 | |
298 | 298 | // Find if db_fileds contains a *, i so assume all col are selected |
299 | - if(strstr($this->options['db_fields'], '*')){ |
|
299 | + if (strstr($this->options['db_fields'], '*')) { |
|
300 | 300 | $sql_from = "*"; |
301 | 301 | } |
302 | - else{ |
|
303 | - $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
302 | + else { |
|
303 | + $sql_from = $this->options['usernamecol'].", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | $query = sprintf("SELECT %s FROM %s", |
@@ -346,8 +346,8 @@ discard block |
||
346 | 346 | |
347 | 347 | if (is_array($additional)) { |
348 | 348 | foreach ($additional as $key => $value) { |
349 | - $additional_key .= ', ' . $key; |
|
350 | - $additional_value .= ", '" . $value . "'"; |
|
349 | + $additional_key .= ', '.$key; |
|
350 | + $additional_value .= ", '".$value."'"; |
|
351 | 351 | } |
352 | 352 | } |
353 | 353 | |
@@ -401,13 +401,13 @@ discard block |
||
401 | 401 | // }}} |
402 | 402 | } |
403 | 403 | |
404 | -function showDbg( $string ) { |
|
404 | +function showDbg($string) { |
|
405 | 405 | print " |
406 | 406 | -- $string</P>"; |
407 | 407 | } |
408 | -function dump( $var, $str, $vardump = false ) { |
|
408 | +function dump($var, $str, $vardump = false) { |
|
409 | 409 | print "<H4>$str</H4><pre>"; |
410 | - ( !$vardump ) ? ( print_r( $var )) : ( var_dump( $var )); |
|
410 | + (!$vardump) ? (print_r($var)) : (var_dump($var)); |
|
411 | 411 | print "</pre>"; |
412 | 412 | } |
413 | 413 | ?> |
@@ -73,13 +73,17 @@ discard block |
||
73 | 73 | { |
74 | 74 | $this->_setDefaults(); |
75 | 75 | |
76 | - if (is_array($dsn)) { |
|
76 | + if (is_array($dsn)) |
|
77 | + { |
|
77 | 78 | $this->_parseOptions($dsn); |
78 | 79 | |
79 | - if (empty($this->options['dsn'])) { |
|
80 | + if (empty($this->options['dsn'])) |
|
81 | + { |
|
80 | 82 | PEAR::raiseError('No connection parameters specified!'); |
81 | 83 | } |
82 | - } else { |
|
84 | + } |
|
85 | + else |
|
86 | + { |
|
83 | 87 | // Extract db_type from dsn string. |
84 | 88 | $this->options['dsn'] = $dsn; |
85 | 89 | } |
@@ -96,16 +100,21 @@ discard block |
||
96 | 100 | * @return mixed Object on error, otherwise bool |
97 | 101 | */ |
98 | 102 | function _connect($dsn) |
99 | - { |
|
100 | - if (is_string($dsn) || is_array($dsn)) { |
|
101 | - if(!$this->db) { |
|
103 | + { |
|
104 | + if (is_string($dsn) || is_array($dsn)) |
|
105 | + { |
|
106 | + if(!$this->db) |
|
107 | + { |
|
102 | 108 | $this->db = &ADONewConnection($dsn); |
103 | - if( $err = ADODB_Pear_error() ) { |
|
109 | + if( $err = ADODB_Pear_error() ) |
|
110 | + { |
|
104 | 111 | return PEAR::raiseError($err); |
105 | 112 | } |
106 | 113 | } |
107 | 114 | |
108 | - } else { |
|
115 | + } |
|
116 | + else |
|
117 | + { |
|
109 | 118 | return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__, |
110 | 119 | 41, |
111 | 120 | PEAR_ERROR_RETURN, |
@@ -114,9 +123,12 @@ discard block |
||
114 | 123 | ); |
115 | 124 | } |
116 | 125 | |
117 | - if(!$this->db) { |
|
126 | + if(!$this->db) |
|
127 | + { |
|
118 | 128 | return PEAR::raiseError(ADODB_Pear_error()); |
119 | - } else { |
|
129 | + } |
|
130 | + else |
|
131 | + { |
|
120 | 132 | return true; |
121 | 133 | } |
122 | 134 | } |
@@ -135,7 +147,8 @@ discard block |
||
135 | 147 | */ |
136 | 148 | function _prepare() |
137 | 149 | { |
138 | - if(!$this->db) { |
|
150 | + if(!$this->db) |
|
151 | + { |
|
139 | 152 | $res = $this->_connect($this->options['dsn']); |
140 | 153 | } |
141 | 154 | return true; |
@@ -159,7 +172,8 @@ discard block |
||
159 | 172 | function query($query) |
160 | 173 | { |
161 | 174 | $err = $this->_prepare(); |
162 | - if ($err !== true) { |
|
175 | + if ($err !== true) |
|
176 | + { |
|
163 | 177 | return $err; |
164 | 178 | } |
165 | 179 | return $this->db->query($query); |
@@ -196,15 +210,19 @@ discard block |
||
196 | 210 | */ |
197 | 211 | function _parseOptions($array) |
198 | 212 | { |
199 | - foreach ($array as $key => $value) { |
|
200 | - if (isset($this->options[$key])) { |
|
213 | + foreach ($array as $key => $value) |
|
214 | + { |
|
215 | + if (isset($this->options[$key])) |
|
216 | + { |
|
201 | 217 | $this->options[$key] = $value; |
202 | 218 | } |
203 | 219 | } |
204 | 220 | |
205 | 221 | /* Include additional fields if they exist */ |
206 | - if(!empty($this->options['db_fields'])){ |
|
207 | - if(is_array($this->options['db_fields'])){ |
|
222 | + if(!empty($this->options['db_fields'])) |
|
223 | + { |
|
224 | + if(is_array($this->options['db_fields'])) |
|
225 | + { |
|
208 | 226 | $this->options['db_fields'] = join($this->options['db_fields'], ', '); |
209 | 227 | } |
210 | 228 | $this->options['db_fields'] = ', '.$this->options['db_fields']; |
@@ -231,15 +249,18 @@ discard block |
||
231 | 249 | { |
232 | 250 | // Prepare for a database query |
233 | 251 | $err = $this->_prepare(); |
234 | - if ($err !== true) { |
|
252 | + if ($err !== true) |
|
253 | + { |
|
235 | 254 | return PEAR::raiseError($err->getMessage(), $err->getCode()); |
236 | 255 | } |
237 | 256 | |
238 | 257 | // Find if db_fields contains a *, i so assume all col are selected |
239 | - if(strstr($this->options['db_fields'], '*')){ |
|
258 | + if(strstr($this->options['db_fields'], '*')) |
|
259 | + { |
|
240 | 260 | $sql_from = "*"; |
241 | 261 | } |
242 | - else{ |
|
262 | + else |
|
263 | + { |
|
243 | 264 | $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
244 | 265 | } |
245 | 266 | |
@@ -251,27 +272,35 @@ discard block |
||
251 | 272 | $rset = $this->db->Execute( $query ); |
252 | 273 | $res = $rset->fetchRow(); |
253 | 274 | |
254 | - if (DB::isError($res)) { |
|
275 | + if (DB::isError($res)) |
|
276 | + { |
|
255 | 277 | return PEAR::raiseError($res->getMessage(), $res->getCode()); |
256 | 278 | } |
257 | - if (!is_array($res)) { |
|
279 | + if (!is_array($res)) |
|
280 | + { |
|
258 | 281 | $this->activeUser = ''; |
259 | 282 | return false; |
260 | 283 | } |
261 | 284 | if ($this->verifyPassword(trim($password, "\r\n"), |
262 | 285 | trim($res[$this->options['passwordcol']], "\r\n"), |
263 | - $this->options['cryptType'])) { |
|
286 | + $this->options['cryptType'])) |
|
287 | + { |
|
264 | 288 | // Store additional field values in the session |
265 | - foreach ($res as $key => $value) { |
|
289 | + foreach ($res as $key => $value) |
|
290 | + { |
|
266 | 291 | if ($key == $this->options['passwordcol'] || |
267 | - $key == $this->options['usernamecol']) { |
|
292 | + $key == $this->options['usernamecol']) |
|
293 | + { |
|
268 | 294 | continue; |
269 | 295 | } |
270 | 296 | // Use reference to the auth object if exists |
271 | 297 | // This is because the auth session variable can change so a static call to setAuthData does not make sence |
272 | - if(is_object($this->_auth_obj)){ |
|
298 | + if(is_object($this->_auth_obj)) |
|
299 | + { |
|
273 | 300 | $this->_auth_obj->setAuthData($key, $value); |
274 | - } else { |
|
301 | + } |
|
302 | + else |
|
303 | + { |
|
275 | 304 | Auth::setAuthData($key, $value); |
276 | 305 | } |
277 | 306 | } |
@@ -289,17 +318,20 @@ discard block |
||
289 | 318 | function listUsers() |
290 | 319 | { |
291 | 320 | $err = $this->_prepare(); |
292 | - if ($err !== true) { |
|
321 | + if ($err !== true) |
|
322 | + { |
|
293 | 323 | return PEAR::raiseError($err->getMessage(), $err->getCode()); |
294 | 324 | } |
295 | 325 | |
296 | 326 | $retVal = array(); |
297 | 327 | |
298 | 328 | // Find if db_fileds contains a *, i so assume all col are selected |
299 | - if(strstr($this->options['db_fields'], '*')){ |
|
329 | + if(strstr($this->options['db_fields'], '*')) |
|
330 | + { |
|
300 | 331 | $sql_from = "*"; |
301 | 332 | } |
302 | - else{ |
|
333 | + else |
|
334 | + { |
|
303 | 335 | $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
304 | 336 | } |
305 | 337 | |
@@ -309,10 +341,14 @@ discard block |
||
309 | 341 | ); |
310 | 342 | $res = $this->db->getAll($query, null, DB_FETCHMODE_ASSOC); |
311 | 343 | |
312 | - if (DB::isError($res)) { |
|
344 | + if (DB::isError($res)) |
|
345 | + { |
|
313 | 346 | return PEAR::raiseError($res->getMessage(), $res->getCode()); |
314 | - } else { |
|
315 | - foreach ($res as $user) { |
|
347 | + } |
|
348 | + else |
|
349 | + { |
|
350 | + foreach ($res as $user) |
|
351 | + { |
|
316 | 352 | $user['username'] = $user[$this->options['usernamecol']]; |
317 | 353 | $retVal[] = $user; |
318 | 354 | } |
@@ -335,17 +371,22 @@ discard block |
||
335 | 371 | */ |
336 | 372 | function addUser($username, $password, $additional = "") |
337 | 373 | { |
338 | - if (function_exists($this->options['cryptType'])) { |
|
374 | + if (function_exists($this->options['cryptType'])) |
|
375 | + { |
|
339 | 376 | $cryptFunction = $this->options['cryptType']; |
340 | - } else { |
|
377 | + } |
|
378 | + else |
|
379 | + { |
|
341 | 380 | $cryptFunction = 'md5'; |
342 | 381 | } |
343 | 382 | |
344 | 383 | $additional_key = ''; |
345 | 384 | $additional_value = ''; |
346 | 385 | |
347 | - if (is_array($additional)) { |
|
348 | - foreach ($additional as $key => $value) { |
|
386 | + if (is_array($additional)) |
|
387 | + { |
|
388 | + foreach ($additional as $key => $value) |
|
389 | + { |
|
349 | 390 | $additional_key .= ', ' . $key; |
350 | 391 | $additional_value .= ", '" . $value . "'"; |
351 | 392 | } |
@@ -363,9 +404,12 @@ discard block |
||
363 | 404 | |
364 | 405 | $res = $this->query($query); |
365 | 406 | |
366 | - if (DB::isError($res)) { |
|
407 | + if (DB::isError($res)) |
|
408 | + { |
|
367 | 409 | return PEAR::raiseError($res->getMessage(), $res->getCode()); |
368 | - } else { |
|
410 | + } |
|
411 | + else |
|
412 | + { |
|
369 | 413 | return true; |
370 | 414 | } |
371 | 415 | } |
@@ -391,9 +435,12 @@ discard block |
||
391 | 435 | |
392 | 436 | $res = $this->query($query); |
393 | 437 | |
394 | - if (DB::isError($res)) { |
|
438 | + if (DB::isError($res)) |
|
439 | + { |
|
395 | 440 | return PEAR::raiseError($res->getMessage(), $res->getCode()); |
396 | - } else { |
|
441 | + } |
|
442 | + else |
|
443 | + { |
|
397 | 444 | return true; |
398 | 445 | } |
399 | 446 | } |
@@ -401,11 +448,13 @@ discard block |
||
401 | 448 | // }}} |
402 | 449 | } |
403 | 450 | |
404 | -function showDbg( $string ) { |
|
451 | +function showDbg( $string ) |
|
452 | +{ |
|
405 | 453 | print " |
406 | 454 | -- $string</P>"; |
407 | 455 | } |
408 | -function dump( $var, $str, $vardump = false ) { |
|
456 | +function dump( $var, $str, $vardump = false ) |
|
457 | +{ |
|
409 | 458 | print "<H4>$str</H4><pre>"; |
410 | 459 | ( !$vardump ) ? ( print_r( $var )) : ( var_dump( $var )); |
411 | 460 | print "</pre>"; |
@@ -320,6 +320,10 @@ |
||
320 | 320 | /* |
321 | 321 | Generate html for suspicious/expensive sql |
322 | 322 | */ |
323 | + |
|
324 | + /** |
|
325 | + * @param string $type |
|
326 | + */ |
|
323 | 327 | function tohtml(&$rs,$type) |
324 | 328 | { |
325 | 329 | $o1 = $rs->FetchField(0); |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | // security - hide paths |
16 | 16 | if (!defined('ADODB_DIR')) die(); |
17 | 17 | |
18 | -class perf_oci8 extends ADODB_perf{ |
|
18 | +class perf_oci8 extends ADODB_perf { |
|
19 | 19 | |
20 | 20 | var $tablesSQL = "select segment_name as \"tablename\", sum(bytes)/1024 as \"size_in_k\",tablespace_name as \"tablespace\",count(*) \"extents\" from sys.user_extents |
21 | 21 | group by segment_name,tablespace_name"; |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | phy.name = 'physical reads'", |
41 | 41 | '=WarnCacheRatio'), |
42 | 42 | |
43 | - 'sql cache hit ratio' => array( 'RATIOH', |
|
43 | + 'sql cache hit ratio' => array('RATIOH', |
|
44 | 44 | 'select round(100*(sum(pins)-sum(reloads))/sum(pins),2) from v$librarycache', |
45 | 45 | 'increase <i>shared_pool_size</i> if too ratio low'), |
46 | 46 | |
@@ -68,37 +68,37 @@ discard block |
||
68 | 68 | "select value from v\$sysstat where name='physical writes'"), |
69 | 69 | |
70 | 70 | 'Data Cache', |
71 | - 'data cache buffers' => array( 'DATAC', |
|
71 | + 'data cache buffers' => array('DATAC', |
|
72 | 72 | "select a.value/b.value from v\$parameter a, v\$parameter b |
73 | 73 | where a.name = 'db_cache_size' and b.name= 'db_block_size'", |
74 | 74 | 'Number of cache buffers. Tune <i>db_cache_size</i> if the <i>data cache hit ratio</i> is too low.'), |
75 | 75 | 'data cache blocksize' => array('DATAC', |
76 | 76 | "select value from v\$parameter where name='db_block_size'", |
77 | - '' ), |
|
77 | + ''), |
|
78 | 78 | 'Memory Pools', |
79 | 79 | 'data cache size' => array('DATAC', |
80 | 80 | "select value from v\$parameter where name = 'db_cache_size'", |
81 | - 'db_cache_size' ), |
|
81 | + 'db_cache_size'), |
|
82 | 82 | 'shared pool size' => array('DATAC', |
83 | 83 | "select value from v\$parameter where name = 'shared_pool_size'", |
84 | - 'shared_pool_size, which holds shared sql, stored procedures, dict cache and similar shared structs' ), |
|
84 | + 'shared_pool_size, which holds shared sql, stored procedures, dict cache and similar shared structs'), |
|
85 | 85 | 'java pool size' => array('DATAJ', |
86 | 86 | "select value from v\$parameter where name = 'java_pool_size'", |
87 | - 'java_pool_size' ), |
|
87 | + 'java_pool_size'), |
|
88 | 88 | 'large pool buffer size' => array('CACHE', |
89 | 89 | "select value from v\$parameter where name='large_pool_size'", |
90 | - 'this pool is for large mem allocations (not because it is larger than shared pool), for MTS sessions, parallel queries, io buffers (large_pool_size) ' ), |
|
90 | + 'this pool is for large mem allocations (not because it is larger than shared pool), for MTS sessions, parallel queries, io buffers (large_pool_size) '), |
|
91 | 91 | |
92 | 92 | 'pga buffer size' => array('CACHE', |
93 | 93 | "select value from v\$parameter where name='pga_aggregate_target'", |
94 | - 'program global area is private memory for sorting, and hash and bitmap merges - since oracle 9i (pga_aggregate_target)' ), |
|
94 | + 'program global area is private memory for sorting, and hash and bitmap merges - since oracle 9i (pga_aggregate_target)'), |
|
95 | 95 | |
96 | 96 | |
97 | 97 | 'Connections', |
98 | 98 | 'current connections' => array('SESS', |
99 | 99 | 'select count(*) from sys.v_$session where username is not null', |
100 | 100 | ''), |
101 | - 'max connections' => array( 'SESS', |
|
101 | + 'max connections' => array('SESS', |
|
102 | 102 | "select value from v\$parameter where name='sessions'", |
103 | 103 | ''), |
104 | 104 | |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | 'Percentage of large_pool actually in use - too low is bad, too high is worse'), |
124 | 124 | 'sort buffer size' => array('CACHE', |
125 | 125 | "select value from v\$parameter where name='sort_area_size'", |
126 | - 'max in-mem sort_area_size (per query), uses memory in pga' ), |
|
126 | + 'max in-mem sort_area_size (per query), uses memory in pga'), |
|
127 | 127 | |
128 | 128 | 'pga usage at peak' => array('RATIOU', |
129 | - '=PGA','Mb utilization at peak transactions (requires Oracle 9i+)'), |
|
129 | + '=PGA', 'Mb utilization at peak transactions (requires Oracle 9i+)'), |
|
130 | 130 | 'Transactions', |
131 | 131 | 'rollback segments' => array('ROLLBACK', |
132 | 132 | "select count(*) from sys.v_\$rollstat", |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | $savelog = $conn->LogSQL(false); |
168 | 168 | $this->version = $conn->ServerInfo(); |
169 | 169 | $conn->LogSQL($savelog); |
170 | - $this->conn =& $conn; |
|
170 | + $this->conn = & $conn; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | function WarnPageCost($val) |
@@ -208,10 +208,10 @@ discard block |
||
208 | 208 | return reset($rs->fields); |
209 | 209 | } |
210 | 210 | |
211 | - function Explain($sql,$partial=false) |
|
211 | + function Explain($sql, $partial = false) |
|
212 | 212 | { |
213 | 213 | $savelog = $this->conn->LogSQL(false); |
214 | - $rs =& $this->conn->SelectLimit("select ID FROM PLAN_TABLE"); |
|
214 | + $rs = & $this->conn->SelectLimit("select ID FROM PLAN_TABLE"); |
|
215 | 215 | if (!$rs) { |
216 | 216 | echo "<p><b>Missing PLAN_TABLE</b></p> |
217 | 217 | <pre> |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | $sqlq = $this->conn->qstr($sql.'%'); |
253 | 253 | $arr = $this->conn->GetArray("select distinct distinct sql1 from adodb_logsql where sql1 like $sqlq"); |
254 | 254 | if ($arr) { |
255 | - foreach($arr as $row) { |
|
255 | + foreach ($arr as $row) { |
|
256 | 256 | $sql = reset($row); |
257 | 257 | if (crc32($sql) == $partial) break; |
258 | 258 | } |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | $this->conn->BeginTrans(); |
265 | 265 | $id = "ADODB ".microtime(); |
266 | 266 | |
267 | - $rs =& $this->conn->Execute("EXPLAIN PLAN SET STATEMENT_ID='$id' FOR $sql"); |
|
267 | + $rs = & $this->conn->Execute("EXPLAIN PLAN SET STATEMENT_ID='$id' FOR $sql"); |
|
268 | 268 | $m = $this->conn->ErrorMsg(); |
269 | 269 | if ($m) { |
270 | 270 | $this->conn->RollbackTrans(); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | $s .= "<p>$m</p>"; |
273 | 273 | return $s; |
274 | 274 | } |
275 | - $rs =& $this->conn->Execute(" |
|
275 | + $rs = & $this->conn->Execute(" |
|
276 | 276 | select |
277 | 277 | '<pre>'||lpad('--', (level-1)*2,'-') || trim(operation) || ' ' || trim(options)||'</pre>' as Operation, |
278 | 278 | object_name,COST,CARDINALITY,bytes |
@@ -280,10 +280,10 @@ discard block |
||
280 | 280 | START WITH id = 0 and STATEMENT_ID='$id' |
281 | 281 | CONNECT BY prior id=parent_id and statement_id='$id'"); |
282 | 282 | |
283 | - $s .= rs2html($rs,false,false,false,false); |
|
283 | + $s .= rs2html($rs, false, false, false, false); |
|
284 | 284 | $this->conn->RollbackTrans(); |
285 | 285 | $this->conn->LogSQL($savelog); |
286 | - $s .= $this->Tracer($sql,$partial); |
|
286 | + $s .= $this->Tracer($sql, $partial); |
|
287 | 287 | return $s; |
288 | 288 | } |
289 | 289 | |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | { |
293 | 293 | if ($this->version['version'] < 9) return 'Oracle 9i or later required'; |
294 | 294 | |
295 | - $rs =& $this->conn->Execute(" |
|
295 | + $rs = & $this->conn->Execute(" |
|
296 | 296 | select a.size_for_estimate as cache_mb_estimate, |
297 | 297 | case when a.size_factor=1 then |
298 | 298 | '<<= current' |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | $s .= "<p>Cache that is 50% of current size is still too big</p>"; |
313 | 313 | } else { |
314 | 314 | $s .= "Ideal size of Data Cache is when \"best_when_0\" changes from a positive number and becomes zero."; |
315 | - $s .= rs2html($rs,false,false,false,false); |
|
315 | + $s .= rs2html($rs, false, false, false, false); |
|
316 | 316 | } |
317 | 317 | return $s; |
318 | 318 | } |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | /* |
321 | 321 | Generate html for suspicious/expensive sql |
322 | 322 | */ |
323 | - function tohtml(&$rs,$type) |
|
323 | + function tohtml(&$rs, $type) |
|
324 | 324 | { |
325 | 325 | $o1 = $rs->FetchField(0); |
326 | 326 | $o2 = $rs->FetchField(1); |
@@ -332,33 +332,33 @@ discard block |
||
332 | 332 | while (!$rs->EOF) { |
333 | 333 | if ($check != $rs->fields[0].'::'.$rs->fields[1]) { |
334 | 334 | if ($check) { |
335 | - $carr = explode('::',$check); |
|
335 | + $carr = explode('::', $check); |
|
336 | 336 | $prefix = "<a href=\"?$type=1&sql=".rawurlencode($sql).'&x#explain">'; |
337 | 337 | $suffix = '</a>'; |
338 | - if (strlen($prefix)>2000) { |
|
338 | + if (strlen($prefix) > 2000) { |
|
339 | 339 | $prefix = ''; |
340 | 340 | $suffix = ''; |
341 | 341 | } |
342 | 342 | |
343 | - $s .= "\n<tr><td align=right>".$carr[0].'</td><td align=right>'.$carr[1].'</td><td>'.$prefix.$sql.$suffix.'</td></tr>'; |
|
343 | + $s .= "\n<tr><td align=right>".$carr[0].'</td><td align=right>'.$carr[1].'</td><td>'.$prefix.$sql.$suffix.'</td></tr>'; |
|
344 | 344 | } |
345 | 345 | $sql = $rs->fields[2]; |
346 | 346 | $check = $rs->fields[0].'::'.$rs->fields[1]; |
347 | 347 | } else |
348 | 348 | $sql .= $rs->fields[2]; |
349 | - if (substr($sql,strlen($sql)-1) == "\0") $sql = substr($sql,0,strlen($sql)-1); |
|
349 | + if (substr($sql, strlen($sql) - 1) == "\0") $sql = substr($sql, 0, strlen($sql) - 1); |
|
350 | 350 | $rs->MoveNext(); |
351 | 351 | } |
352 | 352 | $rs->Close(); |
353 | 353 | |
354 | - $carr = explode('::',$check); |
|
354 | + $carr = explode('::', $check); |
|
355 | 355 | $prefix = "<a target=".rand()." href=\"?&hidem=1&$type=1&sql=".rawurlencode($sql).'&x#explain">'; |
356 | 356 | $suffix = '</a>'; |
357 | - if (strlen($prefix)>2000) { |
|
357 | + if (strlen($prefix) > 2000) { |
|
358 | 358 | $prefix = ''; |
359 | 359 | $suffix = ''; |
360 | 360 | } |
361 | - $s .= "\n<tr><td align=right>".$carr[0].'</td><td align=right>'.$carr[1].'</td><td>'.$prefix.$sql.$suffix.'</td></tr>'; |
|
361 | + $s .= "\n<tr><td align=right>".$carr[0].'</td><td align=right>'.$carr[1].'</td><td>'.$prefix.$sql.$suffix.'</td></tr>'; |
|
362 | 362 | |
363 | 363 | return $s."</table>\n\n"; |
364 | 364 | } |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | // code thanks to Ixora. |
367 | 367 | // http://www.ixora.com.au/scripts/query_opt.htm |
368 | 368 | // requires oracle 8.1.7 or later |
369 | - function SuspiciousSQL($numsql=10) |
|
369 | + function SuspiciousSQL($numsql = 10) |
|
370 | 370 | { |
371 | 371 | $sql = " |
372 | 372 | select |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | global $ADODB_CACHE_MODE; |
407 | 407 | if (isset($_GET['expsixora']) && isset($_GET['sql'])) { |
408 | 408 | $partial = empty($_GET['part']); |
409 | - echo "<a name=explain></a>".$this->Explain($_GET['sql'],$partial)."\n"; |
|
409 | + echo "<a name=explain></a>".$this->Explain($_GET['sql'], $partial)."\n"; |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | if (isset($_GET['sql'])) return $this->_SuspiciousSQL($numsql); |
@@ -420,14 +420,14 @@ discard block |
||
420 | 420 | if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
421 | 421 | |
422 | 422 | $savelog = $this->conn->LogSQL(false); |
423 | - $rs =& $this->conn->SelectLimit($sql); |
|
423 | + $rs = & $this->conn->SelectLimit($sql); |
|
424 | 424 | $this->conn->LogSQL($savelog); |
425 | 425 | |
426 | 426 | if (isset($savem)) $this->conn->SetFetchMode($savem); |
427 | 427 | $ADODB_CACHE_MODE = $save; |
428 | 428 | if ($rs) { |
429 | 429 | $s .= "\n<h3>Ixora Suspicious SQL</h3>"; |
430 | - $s .= $this->tohtml($rs,'expsixora'); |
|
430 | + $s .= $this->tohtml($rs, 'expsixora'); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | return $s; |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | global $ADODB_CACHE_MODE; |
477 | 477 | if (isset($_GET['expeixora']) && isset($_GET['sql'])) { |
478 | 478 | $partial = empty($_GET['part']); |
479 | - echo "<a name=explain></a>".$this->Explain($_GET['sql'],$partial)."\n"; |
|
479 | + echo "<a name=explain></a>".$this->Explain($_GET['sql'], $partial)."\n"; |
|
480 | 480 | } |
481 | 481 | if (isset($_GET['sql'])) { |
482 | 482 | $var = $this->_ExpensiveSQL($numsql); |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
492 | 492 | |
493 | 493 | $savelog = $this->conn->LogSQL(false); |
494 | - $rs =& $this->conn->Execute($sql); |
|
494 | + $rs = & $this->conn->Execute($sql); |
|
495 | 495 | $this->conn->LogSQL($savelog); |
496 | 496 | |
497 | 497 | if (isset($savem)) $this->conn->SetFetchMode($savem); |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | |
500 | 500 | if ($rs) { |
501 | 501 | $s .= "\n<h3>Ixora Expensive SQL</h3>"; |
502 | - $s .= $this->tohtml($rs,'expeixora'); |
|
502 | + $s .= $this->tohtml($rs, 'expeixora'); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | return $s; |
@@ -13,9 +13,13 @@ discard block |
||
13 | 13 | */ |
14 | 14 | |
15 | 15 | // security - hide paths |
16 | -if (!defined('ADODB_DIR')) die(); |
|
16 | +if (!defined('ADODB_DIR')) |
|
17 | +{ |
|
18 | + die(); |
|
19 | +} |
|
17 | 20 | |
18 | -class perf_oci8 extends ADODB_perf{ |
|
21 | +class perf_oci8 extends ADODB_perf |
|
22 | +{ |
|
19 | 23 | |
20 | 24 | var $tablesSQL = "select segment_name as \"tablename\", sum(bytes)/1024 as \"size_in_k\",tablespace_name as \"tablespace\",count(*) \"extents\" from sys.user_extents |
21 | 25 | group by segment_name,tablespace_name"; |
@@ -172,16 +176,26 @@ discard block |
||
172 | 176 | |
173 | 177 | function WarnPageCost($val) |
174 | 178 | { |
175 | - if ($val == 100) $s = '<font color=red><b>Too High</b>. </font>'; |
|
176 | - else $s = ''; |
|
179 | + if ($val == 100) |
|
180 | + { |
|
181 | + $s = '<font color=red><b>Too High</b>. </font>'; |
|
182 | + } |
|
183 | + else { |
|
184 | + $s = ''; |
|
185 | + } |
|
177 | 186 | |
178 | 187 | return $s.'Recommended is 20-50 for TP, and 50 for data warehouses. Default is 100. See <a href=http://www.dba-oracle.com/oracle_tips_cost_adj.htm>optimizer_index_cost_adj</a>. '; |
179 | 188 | } |
180 | 189 | |
181 | 190 | function WarnIndexCost($val) |
182 | 191 | { |
183 | - if ($val == 0) $s = '<font color=red><b>Too Low</b>. </font>'; |
|
184 | - else $s = ''; |
|
192 | + if ($val == 0) |
|
193 | + { |
|
194 | + $s = '<font color=red><b>Too Low</b>. </font>'; |
|
195 | + } |
|
196 | + else { |
|
197 | + $s = ''; |
|
198 | + } |
|
185 | 199 | |
186 | 200 | return $s.'Percentage of indexed data blocks expected in the cache. |
187 | 201 | Recommended is 20 (fast disk array) to 50 (slower hard disks). Default is 0. |
@@ -190,7 +204,10 @@ discard block |
||
190 | 204 | |
191 | 205 | function PGA() |
192 | 206 | { |
193 | - if ($this->version['version'] < 9) return 'Oracle 9i or later required'; |
|
207 | + if ($this->version['version'] < 9) |
|
208 | + { |
|
209 | + return 'Oracle 9i or later required'; |
|
210 | + } |
|
194 | 211 | |
195 | 212 | $rs = $this->conn->Execute("select a.mb,a.targ as pga_size_pct,a.pct from |
196 | 213 | (select round(pga_target_for_estimate/1024.0/1024.0,0) Mb, |
@@ -201,18 +218,25 @@ discard block |
||
201 | 218 | from v\$pga_target_advice) b on |
202 | 219 | a.r = b.r+1 where |
203 | 220 | b.pct < 100"); |
204 | - if (!$rs) return "Only in 9i or later"; |
|
221 | + if (!$rs) |
|
222 | + { |
|
223 | + return "Only in 9i or later"; |
|
224 | + } |
|
205 | 225 | $rs->Close(); |
206 | - if ($rs->EOF) return "PGA could be too big"; |
|
226 | + if ($rs->EOF) |
|
227 | + { |
|
228 | + return "PGA could be too big"; |
|
229 | + } |
|
207 | 230 | |
208 | 231 | return reset($rs->fields); |
209 | 232 | } |
210 | 233 | |
211 | - function Explain($sql,$partial=false) |
|
234 | + function Explain($sql,$partial=false) |
|
212 | 235 | { |
213 | 236 | $savelog = $this->conn->LogSQL(false); |
214 | 237 | $rs =& $this->conn->SelectLimit("select ID FROM PLAN_TABLE"); |
215 | - if (!$rs) { |
|
238 | + if (!$rs) |
|
239 | + { |
|
216 | 240 | echo "<p><b>Missing PLAN_TABLE</b></p> |
217 | 241 | <pre> |
218 | 242 | CREATE TABLE PLAN_TABLE ( |
@@ -248,13 +272,19 @@ discard block |
||
248 | 272 | $rs->Close(); |
249 | 273 | // $this->conn->debug=1; |
250 | 274 | |
251 | - if ($partial) { |
|
275 | + if ($partial) |
|
276 | + { |
|
252 | 277 | $sqlq = $this->conn->qstr($sql.'%'); |
253 | 278 | $arr = $this->conn->GetArray("select distinct distinct sql1 from adodb_logsql where sql1 like $sqlq"); |
254 | - if ($arr) { |
|
255 | - foreach($arr as $row) { |
|
279 | + if ($arr) |
|
280 | + { |
|
281 | + foreach($arr as $row) |
|
282 | + { |
|
256 | 283 | $sql = reset($row); |
257 | - if (crc32($sql) == $partial) break; |
|
284 | + if (crc32($sql) == $partial) |
|
285 | + { |
|
286 | + break; |
|
287 | + } |
|
258 | 288 | } |
259 | 289 | } |
260 | 290 | } |
@@ -266,7 +296,8 @@ discard block |
||
266 | 296 | |
267 | 297 | $rs =& $this->conn->Execute("EXPLAIN PLAN SET STATEMENT_ID='$id' FOR $sql"); |
268 | 298 | $m = $this->conn->ErrorMsg(); |
269 | - if ($m) { |
|
299 | + if ($m) |
|
300 | + { |
|
270 | 301 | $this->conn->RollbackTrans(); |
271 | 302 | $this->conn->LogSQL($savelog); |
272 | 303 | $s .= "<p>$m</p>"; |
@@ -290,7 +321,10 @@ discard block |
||
290 | 321 | |
291 | 322 | function CheckMemory() |
292 | 323 | { |
293 | - if ($this->version['version'] < 9) return 'Oracle 9i or later required'; |
|
324 | + if ($this->version['version'] < 9) |
|
325 | + { |
|
326 | + return 'Oracle 9i or later required'; |
|
327 | + } |
|
294 | 328 | |
295 | 329 | $rs =& $this->conn->Execute(" |
296 | 330 | select a.size_for_estimate as cache_mb_estimate, |
@@ -302,15 +336,21 @@ discard block |
||
302 | 336 | a.estd_physical_read_factor-b.estd_physical_read_factor as best_when_0 |
303 | 337 | from (select size_for_estimate,size_factor,estd_physical_read_factor,rownum r from v\$db_cache_advice) a , |
304 | 338 | (select size_for_estimate,size_factor,estd_physical_read_factor,rownum r from v\$db_cache_advice) b where a.r = b.r-1"); |
305 | - if (!$rs) return false; |
|
339 | + if (!$rs) |
|
340 | + { |
|
341 | + return false; |
|
342 | + } |
|
306 | 343 | |
307 | 344 | /* |
308 | 345 | The v$db_cache_advice utility show the marginal changes in physical data block reads for different sizes of db_cache_size |
309 | 346 | */ |
310 | 347 | $s = "<h3>Data Cache Estimate</h3>"; |
311 | - if ($rs->EOF) { |
|
348 | + if ($rs->EOF) |
|
349 | + { |
|
312 | 350 | $s .= "<p>Cache that is 50% of current size is still too big</p>"; |
313 | - } else { |
|
351 | + } |
|
352 | + else |
|
353 | + { |
|
314 | 354 | $s .= "Ideal size of Data Cache is when \"best_when_0\" changes from a positive number and becomes zero."; |
315 | 355 | $s .= rs2html($rs,false,false,false,false); |
316 | 356 | } |
@@ -325,17 +365,24 @@ discard block |
||
325 | 365 | $o1 = $rs->FetchField(0); |
326 | 366 | $o2 = $rs->FetchField(1); |
327 | 367 | $o3 = $rs->FetchField(2); |
328 | - if ($rs->EOF) return '<p>None found</p>'; |
|
368 | + if ($rs->EOF) |
|
369 | + { |
|
370 | + return '<p>None found</p>'; |
|
371 | + } |
|
329 | 372 | $check = ''; |
330 | 373 | $sql = ''; |
331 | 374 | $s = "\n\n<table border=1 bgcolor=white><tr><td><b>".$o1->name.'</b></td><td><b>'.$o2->name.'</b></td><td><b>'.$o3->name.'</b></td></tr>'; |
332 | - while (!$rs->EOF) { |
|
333 | - if ($check != $rs->fields[0].'::'.$rs->fields[1]) { |
|
334 | - if ($check) { |
|
375 | + while (!$rs->EOF) |
|
376 | + { |
|
377 | + if ($check != $rs->fields[0].'::'.$rs->fields[1]) |
|
378 | + { |
|
379 | + if ($check) |
|
380 | + { |
|
335 | 381 | $carr = explode('::',$check); |
336 | 382 | $prefix = "<a href=\"?$type=1&sql=".rawurlencode($sql).'&x#explain">'; |
337 | 383 | $suffix = '</a>'; |
338 | - if (strlen($prefix)>2000) { |
|
384 | + if (strlen($prefix)>2000) |
|
385 | + { |
|
339 | 386 | $prefix = ''; |
340 | 387 | $suffix = ''; |
341 | 388 | } |
@@ -344,9 +391,14 @@ discard block |
||
344 | 391 | } |
345 | 392 | $sql = $rs->fields[2]; |
346 | 393 | $check = $rs->fields[0].'::'.$rs->fields[1]; |
347 | - } else |
|
348 | - $sql .= $rs->fields[2]; |
|
349 | - if (substr($sql,strlen($sql)-1) == "\0") $sql = substr($sql,0,strlen($sql)-1); |
|
394 | + } |
|
395 | + else { |
|
396 | + $sql .= $rs->fields[2]; |
|
397 | + } |
|
398 | + if (substr($sql,strlen($sql)-1) == "\0") |
|
399 | + { |
|
400 | + $sql = substr($sql,0,strlen($sql)-1); |
|
401 | + } |
|
350 | 402 | $rs->MoveNext(); |
351 | 403 | } |
352 | 404 | $rs->Close(); |
@@ -354,7 +406,8 @@ discard block |
||
354 | 406 | $carr = explode('::',$check); |
355 | 407 | $prefix = "<a target=".rand()." href=\"?&hidem=1&$type=1&sql=".rawurlencode($sql).'&x#explain">'; |
356 | 408 | $suffix = '</a>'; |
357 | - if (strlen($prefix)>2000) { |
|
409 | + if (strlen($prefix)>2000) |
|
410 | + { |
|
358 | 411 | $prefix = ''; |
359 | 412 | $suffix = ''; |
360 | 413 | } |
@@ -404,12 +457,16 @@ discard block |
||
404 | 457 | 1 desc, s.address, p.piece"; |
405 | 458 | |
406 | 459 | global $ADODB_CACHE_MODE; |
407 | - if (isset($_GET['expsixora']) && isset($_GET['sql'])) { |
|
460 | + if (isset($_GET['expsixora']) && isset($_GET['sql'])) |
|
461 | + { |
|
408 | 462 | $partial = empty($_GET['part']); |
409 | 463 | echo "<a name=explain></a>".$this->Explain($_GET['sql'],$partial)."\n"; |
410 | 464 | } |
411 | 465 | |
412 | - if (isset($_GET['sql'])) return $this->_SuspiciousSQL($numsql); |
|
466 | + if (isset($_GET['sql'])) |
|
467 | + { |
|
468 | + return $this->_SuspiciousSQL($numsql); |
|
469 | + } |
|
413 | 470 | |
414 | 471 | $s = ''; |
415 | 472 | $s .= $this->_SuspiciousSQL($numsql); |
@@ -417,15 +474,22 @@ discard block |
||
417 | 474 | |
418 | 475 | $save = $ADODB_CACHE_MODE; |
419 | 476 | $ADODB_CACHE_MODE = ADODB_FETCH_NUM; |
420 | - if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
|
477 | + if ($this->conn->fetchMode !== false) |
|
478 | + { |
|
479 | + $savem = $this->conn->SetFetchMode(false); |
|
480 | + } |
|
421 | 481 | |
422 | 482 | $savelog = $this->conn->LogSQL(false); |
423 | 483 | $rs =& $this->conn->SelectLimit($sql); |
424 | 484 | $this->conn->LogSQL($savelog); |
425 | 485 | |
426 | - if (isset($savem)) $this->conn->SetFetchMode($savem); |
|
486 | + if (isset($savem)) |
|
487 | + { |
|
488 | + $this->conn->SetFetchMode($savem); |
|
489 | + } |
|
427 | 490 | $ADODB_CACHE_MODE = $save; |
428 | - if ($rs) { |
|
491 | + if ($rs) |
|
492 | + { |
|
429 | 493 | $s .= "\n<h3>Ixora Suspicious SQL</h3>"; |
430 | 494 | $s .= $this->tohtml($rs,'expsixora'); |
431 | 495 | } |
@@ -474,11 +538,13 @@ discard block |
||
474 | 538 | 1 desc, s.address, p.piece |
475 | 539 | "; |
476 | 540 | global $ADODB_CACHE_MODE; |
477 | - if (isset($_GET['expeixora']) && isset($_GET['sql'])) { |
|
541 | + if (isset($_GET['expeixora']) && isset($_GET['sql'])) |
|
542 | + { |
|
478 | 543 | $partial = empty($_GET['part']); |
479 | 544 | echo "<a name=explain></a>".$this->Explain($_GET['sql'],$partial)."\n"; |
480 | 545 | } |
481 | - if (isset($_GET['sql'])) { |
|
546 | + if (isset($_GET['sql'])) |
|
547 | + { |
|
482 | 548 | $var = $this->_ExpensiveSQL($numsql); |
483 | 549 | return $var; |
484 | 550 | } |
@@ -488,16 +554,23 @@ discard block |
||
488 | 554 | $s .= '<p>'; |
489 | 555 | $save = $ADODB_CACHE_MODE; |
490 | 556 | $ADODB_CACHE_MODE = ADODB_FETCH_NUM; |
491 | - if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
|
557 | + if ($this->conn->fetchMode !== false) |
|
558 | + { |
|
559 | + $savem = $this->conn->SetFetchMode(false); |
|
560 | + } |
|
492 | 561 | |
493 | 562 | $savelog = $this->conn->LogSQL(false); |
494 | 563 | $rs =& $this->conn->Execute($sql); |
495 | 564 | $this->conn->LogSQL($savelog); |
496 | 565 | |
497 | - if (isset($savem)) $this->conn->SetFetchMode($savem); |
|
566 | + if (isset($savem)) |
|
567 | + { |
|
568 | + $this->conn->SetFetchMode($savem); |
|
569 | + } |
|
498 | 570 | $ADODB_CACHE_MODE = $save; |
499 | 571 | |
500 | - if ($rs) { |
|
572 | + if ($rs) |
|
573 | + { |
|
501 | 574 | $s .= "\n<h3>Ixora Expensive SQL</h3>"; |
502 | 575 | $s .= $this->tohtml($rs,'expeixora'); |
503 | 576 | } |
@@ -124,6 +124,10 @@ discard block |
||
124 | 124 | */ |
125 | 125 | /*! |
126 | 126 | */ |
127 | + |
|
128 | + /** |
|
129 | + * @return string |
|
130 | + */ |
|
127 | 131 | function driver($driver = null) { |
128 | 132 | static $_driver = 'mysql'; |
129 | 133 | static $set = false; |
@@ -302,6 +306,10 @@ discard block |
||
302 | 306 | |
303 | 307 | /*! |
304 | 308 | */ |
309 | + |
|
310 | + /** |
|
311 | + * @return string |
|
312 | + */ |
|
305 | 313 | function table($table = null) { |
306 | 314 | static $_table = 'sessions'; |
307 | 315 | static $set = false; |
@@ -359,6 +367,10 @@ discard block |
||
359 | 367 | |
360 | 368 | /*! |
361 | 369 | */ |
370 | + |
|
371 | + /** |
|
372 | + * @return string |
|
373 | + */ |
|
362 | 374 | function clob($clob = null) { |
363 | 375 | static $_clob = false; |
364 | 376 | static $set = false; |
@@ -405,6 +417,10 @@ discard block |
||
405 | 417 | |
406 | 418 | /*! |
407 | 419 | */ |
420 | + |
|
421 | + /** |
|
422 | + * @return string |
|
423 | + */ |
|
408 | 424 | function encryptionKey($encryption_key = null) { |
409 | 425 | static $_encryption_key = 'CRYPTED ADODB SESSIONS ROCK!'; |
410 | 426 | |
@@ -427,6 +443,12 @@ discard block |
||
427 | 443 | |
428 | 444 | /*! |
429 | 445 | */ |
446 | + |
|
447 | + /** |
|
448 | + * @param string $crc |
|
449 | + * |
|
450 | + * @return string |
|
451 | + */ |
|
430 | 452 | function _crc($crc = null) { |
431 | 453 | static $_crc = false; |
432 | 454 | |
@@ -498,6 +520,10 @@ discard block |
||
498 | 520 | |
499 | 521 | If $conn already exists, reuse that connection |
500 | 522 | */ |
523 | + |
|
524 | + /** |
|
525 | + * @param boolean $persist |
|
526 | + */ |
|
501 | 527 | function open($save_path, $session_name, $persist = null) { |
502 | 528 | $conn =& ADODB_Session::_conn(); |
503 | 529 |
@@ -93,15 +93,15 @@ |
||
93 | 93 | */ |
94 | 94 | function adodb_session_create_table($schemaFile=null,$conn = null) |
95 | 95 | { |
96 | - // set default values |
|
97 | - if ($schemaFile===null) $schemaFile = ADODB_SESSION . '/session_schema.xml'; |
|
98 | - if ($conn===null) $conn =& ADODB_Session::_conn(); |
|
96 | + // set default values |
|
97 | + if ($schemaFile===null) $schemaFile = ADODB_SESSION . '/session_schema.xml'; |
|
98 | + if ($conn===null) $conn =& ADODB_Session::_conn(); |
|
99 | 99 | |
100 | 100 | if (!$conn) return 0; |
101 | 101 | |
102 | - $schema = new adoSchema($conn); |
|
103 | - $schema->ParseSchema($schemaFile); |
|
104 | - return $schema->ExecuteSchema(); |
|
102 | + $schema = new adoSchema($conn); |
|
103 | + $schema->ParseSchema($schemaFile); |
|
104 | + return $schema->ExecuteSchema(); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /*! |
@@ -533,10 +533,10 @@ |
||
533 | 533 | |
534 | 534 | if ($persist) { |
535 | 535 | switch($persist) { |
536 | - default: |
|
537 | - case 'P': $ok = $conn->PConnect($host, $user, $password, $database); break; |
|
538 | - case 'C': $ok = $conn->Connect($host, $user, $password, $database); break; |
|
539 | - case 'N': $ok = $conn->NConnect($host, $user, $password, $database); break; |
|
536 | + default: |
|
537 | + case 'P': $ok = $conn->PConnect($host, $user, $password, $database); break; |
|
538 | + case 'C': $ok = $conn->Connect($host, $user, $password, $database); break; |
|
539 | + case 'N': $ok = $conn->NConnect($host, $user, $password, $database); break; |
|
540 | 540 | } |
541 | 541 | } else { |
542 | 542 | $ok = $conn->Connect($host, $user, $password, $database); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | |
28 | 28 | if (!defined('_ADODB_LAYER')) { |
29 | - require_once realpath(dirname(__FILE__) . '/../adodb.inc.php'); |
|
29 | + require_once realpath(dirname(__FILE__).'/../adodb.inc.php'); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | if (defined('ADODB_SESSION')) return 1; |
@@ -43,14 +43,14 @@ discard block |
||
43 | 43 | 3. After urldecode, run the serialized string through this function: |
44 | 44 | |
45 | 45 | */ |
46 | -function adodb_unserialize( $serialized_string ) |
|
46 | +function adodb_unserialize($serialized_string) |
|
47 | 47 | { |
48 | 48 | $variables = array( ); |
49 | - $a = preg_split( "/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); |
|
50 | - for( $i = 0; $i < count( $a ); $i = $i+2 ) { |
|
51 | - $variables[$a[$i]] = unserialize( $a[$i+1] ); |
|
49 | + $a = preg_split("/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE); |
|
50 | + for ($i = 0; $i < count($a); $i = $i + 2) { |
|
51 | + $variables[$a[$i]] = unserialize($a[$i + 1]); |
|
52 | 52 | } |
53 | - return( $variables ); |
|
53 | + return($variables); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /* |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | function adodb_session_regenerate_id() |
61 | 61 | { |
62 | - $conn =& ADODB_Session::_conn(); |
|
62 | + $conn = & ADODB_Session::_conn(); |
|
63 | 63 | if (!$conn) return false; |
64 | 64 | |
65 | 65 | $old_id = session_id(); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | //@session_start(); |
73 | 73 | } |
74 | 74 | $new_id = session_id(); |
75 | - $ok =& $conn->Execute('UPDATE '. ADODB_Session::table(). ' SET sesskey='. $conn->qstr($new_id). ' WHERE sesskey='.$conn->qstr($old_id)); |
|
75 | + $ok = & $conn->Execute('UPDATE '.ADODB_Session::table().' SET sesskey='.$conn->qstr($new_id).' WHERE sesskey='.$conn->qstr($old_id)); |
|
76 | 76 | |
77 | 77 | /* it is possible that the update statement fails due to a collision */ |
78 | 78 | if (!$ok) { |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | @return 0 if failure, 1 if errors, 2 if successful. |
92 | 92 | @author Markus Staab http://www.public-4u.de |
93 | 93 | */ |
94 | -function adodb_session_create_table($schemaFile=null,$conn = null) |
|
94 | +function adodb_session_create_table($schemaFile = null, $conn = null) |
|
95 | 95 | { |
96 | 96 | // set default values |
97 | - if ($schemaFile===null) $schemaFile = ADODB_SESSION . '/session_schema.xml'; |
|
98 | - if ($conn===null) $conn =& ADODB_Session::_conn(); |
|
97 | + if ($schemaFile === null) $schemaFile = ADODB_SESSION.'/session_schema.xml'; |
|
98 | + if ($conn === null) $conn = & ADODB_Session::_conn(); |
|
99 | 99 | |
100 | 100 | if (!$conn) return 0; |
101 | 101 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | static $set = false; |
238 | 238 | |
239 | 239 | if (!is_null($lifetime)) { |
240 | - $_lifetime = (int) $lifetime; |
|
240 | + $_lifetime = (int)$lifetime; |
|
241 | 241 | $set = true; |
242 | 242 | } elseif (!$set) { |
243 | 243 | // backwards compatibility |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | static $set = false; |
265 | 265 | |
266 | 266 | if (!is_null($debug)) { |
267 | - $_debug = (bool) $debug; |
|
267 | + $_debug = (bool)$debug; |
|
268 | 268 | |
269 | 269 | $conn = ADODB_Session::_conn(); |
270 | 270 | if ($conn) { |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | static $set = false; |
327 | 327 | |
328 | 328 | if (!is_null($optimize)) { |
329 | - $_optimize = (bool) $optimize; |
|
329 | + $_optimize = (bool)$optimize; |
|
330 | 330 | $set = true; |
331 | 331 | } elseif (!$set) { |
332 | 332 | // backwards compatibility |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | static $set = false; |
346 | 346 | |
347 | 347 | if (!is_null($sync_seconds)) { |
348 | - $_sync_seconds = (int) $sync_seconds; |
|
348 | + $_sync_seconds = (int)$sync_seconds; |
|
349 | 349 | $set = true; |
350 | 350 | } elseif (!$set) { |
351 | 351 | // backwards compatibility |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | |
422 | 422 | /*! |
423 | 423 | */ |
424 | - function &_conn($conn=null) { |
|
424 | + function &_conn($conn = null) { |
|
425 | 425 | return $GLOBALS['ADODB_SESS_CONN']; |
426 | 426 | } |
427 | 427 | |
@@ -463,8 +463,8 @@ discard block |
||
463 | 463 | /*! |
464 | 464 | */ |
465 | 465 | function _dumprs($rs) { |
466 | - $conn =& ADODB_Session::_conn(); |
|
467 | - $debug = ADODB_Session::debug(); |
|
466 | + $conn = & ADODB_Session::_conn(); |
|
467 | + $debug = ADODB_Session::debug(); |
|
468 | 468 | |
469 | 469 | if (!$conn) { |
470 | 470 | return; |
@@ -499,17 +499,17 @@ discard block |
||
499 | 499 | If $conn already exists, reuse that connection |
500 | 500 | */ |
501 | 501 | function open($save_path, $session_name, $persist = null) { |
502 | - $conn =& ADODB_Session::_conn(); |
|
502 | + $conn = & ADODB_Session::_conn(); |
|
503 | 503 | |
504 | 504 | if ($conn) { |
505 | 505 | return true; |
506 | 506 | } |
507 | 507 | |
508 | - $database = ADODB_Session::database(); |
|
509 | - $debug = ADODB_Session::debug(); |
|
510 | - $driver = ADODB_Session::driver(); |
|
508 | + $database = ADODB_Session::database(); |
|
509 | + $debug = ADODB_Session::debug(); |
|
510 | + $driver = ADODB_Session::driver(); |
|
511 | 511 | $host = ADODB_Session::host(); |
512 | - $password = ADODB_Session::password(); |
|
512 | + $password = ADODB_Session::password(); |
|
513 | 513 | $user = ADODB_Session::user(); |
514 | 514 | |
515 | 515 | if (!is_null($persist)) { |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | # assert('$host'); |
525 | 525 | |
526 | 526 | // cannot use =& below - do not know why... |
527 | - $conn =& ADONewConnection($driver); |
|
527 | + $conn = & ADONewConnection($driver); |
|
528 | 528 | |
529 | 529 | if ($debug) { |
530 | 530 | $conn->debug = true; |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | } |
533 | 533 | |
534 | 534 | if ($persist) { |
535 | - switch($persist) { |
|
535 | + switch ($persist) { |
|
536 | 536 | default: |
537 | 537 | case 'P': $ok = $conn->PConnect($host, $user, $password, $database); break; |
538 | 538 | case 'C': $ok = $conn->Connect($host, $user, $password, $database); break; |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | $ok = $conn->Connect($host, $user, $password, $database); |
543 | 543 | } |
544 | 544 | |
545 | - if ($ok) $GLOBALS['ADODB_SESS_CONN'] =& $conn; |
|
545 | + if ($ok) $GLOBALS['ADODB_SESS_CONN'] = & $conn; |
|
546 | 546 | else |
547 | 547 | ADOConnection::outp('<p>Session: connection failed</p>', false); |
548 | 548 | |
@@ -565,10 +565,10 @@ discard block |
||
565 | 565 | Slurp in the session variables and return the serialized string |
566 | 566 | */ |
567 | 567 | function read($key) { |
568 | - $conn =& ADODB_Session::_conn(); |
|
568 | + $conn = & ADODB_Session::_conn(); |
|
569 | 569 | $data = ADODB_Session::dataFieldName(); |
570 | - $filter = ADODB_Session::filter(); |
|
571 | - $table = ADODB_Session::table(); |
|
570 | + $filter = ADODB_Session::filter(); |
|
571 | + $table = ADODB_Session::table(); |
|
572 | 572 | |
573 | 573 | if (!$conn) { |
574 | 574 | return ''; |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | $qkey = $conn->quote($key); |
580 | 580 | $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : ''; |
581 | 581 | |
582 | - $sql = "SELECT $data FROM $table WHERE $binary sesskey = $qkey AND expiry >= " . time(); |
|
582 | + $sql = "SELECT $data FROM $table WHERE $binary sesskey = $qkey AND expiry >= ".time(); |
|
583 | 583 | /* Lock code does not work as it needs to hold transaction within whole page, and we don't know if |
584 | 584 | developer has commited elsewhere... :( |
585 | 585 | */ |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | # $rs =& $conn->RowLock($table, "$binary sesskey = $qkey AND expiry >= " . time(), $data); |
588 | 588 | #else |
589 | 589 | |
590 | - $rs =& $conn->Execute($sql); |
|
590 | + $rs = & $conn->Execute($sql); |
|
591 | 591 | //ADODB_Session::_dumprs($rs); |
592 | 592 | if ($rs) { |
593 | 593 | if ($rs->EOF) { |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | |
606 | 606 | $rs->Close(); |
607 | 607 | |
608 | - ADODB_Session::_crc(strlen($v) . crc32($v)); |
|
608 | + ADODB_Session::_crc(strlen($v).crc32($v)); |
|
609 | 609 | return $v; |
610 | 610 | } |
611 | 611 | |
@@ -619,15 +619,15 @@ discard block |
||
619 | 619 | */ |
620 | 620 | function write($key, $val) { |
621 | 621 | $clob = ADODB_Session::clob(); |
622 | - $conn =& ADODB_Session::_conn(); |
|
623 | - $crc = ADODB_Session::_crc(); |
|
622 | + $conn = & ADODB_Session::_conn(); |
|
623 | + $crc = ADODB_Session::_crc(); |
|
624 | 624 | $data = ADODB_Session::dataFieldName(); |
625 | - $debug = ADODB_Session::debug(); |
|
625 | + $debug = ADODB_Session::debug(); |
|
626 | 626 | $driver = ADODB_Session::driver(); |
627 | - $expire_notify = ADODB_Session::expireNotify(); |
|
627 | + $expire_notify = ADODB_Session::expireNotify(); |
|
628 | 628 | $filter = ADODB_Session::filter(); |
629 | - $lifetime = ADODB_Session::lifetime(); |
|
630 | - $table = ADODB_Session::table(); |
|
629 | + $lifetime = ADODB_Session::lifetime(); |
|
630 | + $table = ADODB_Session::table(); |
|
631 | 631 | |
632 | 632 | if (!$conn) { |
633 | 633 | return false; |
@@ -642,12 +642,12 @@ discard block |
||
642 | 642 | |
643 | 643 | // crc32 optimization since adodb 2.1 |
644 | 644 | // now we only update expiry date, thx to sebastian thom in adodb 2.32 |
645 | - if ($crc !== false && $crc == (strlen($val) . crc32($val))) { |
|
645 | + if ($crc !== false && $crc == (strlen($val).crc32($val))) { |
|
646 | 646 | if ($debug) { |
647 | 647 | echo '<p>Session: Only updating date - crc32 not changed</p>'; |
648 | 648 | } |
649 | 649 | $sql = "UPDATE $table SET expiry = ".$conn->Param('0')." WHERE $binary sesskey = ".$conn->Param('1')." AND expiry >= ".$conn->Param('2'); |
650 | - $rs =& $conn->Execute($sql,array($expiry,$key,time())); |
|
650 | + $rs = & $conn->Execute($sql, array($expiry, $key, time())); |
|
651 | 651 | ADODB_Session::_dumprs($rs); |
652 | 652 | if ($rs) { |
653 | 653 | $rs->Close(); |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | } |
693 | 693 | |
694 | 694 | // do we insert or update? => as for sesskey |
695 | - $rs =& $conn->Execute("SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = $qkey"); |
|
695 | + $rs = & $conn->Execute("SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = $qkey"); |
|
696 | 696 | ADODB_Session::_dumprs($rs); |
697 | 697 | if ($rs && reset($rs->fields) > 0) { |
698 | 698 | $sql = "UPDATE $table SET expiry = $expiry, $data = $lob_value WHERE sesskey = $qkey"; |
@@ -704,12 +704,12 @@ discard block |
||
704 | 704 | } |
705 | 705 | |
706 | 706 | $err = ''; |
707 | - $rs1 =& $conn->Execute($sql); |
|
707 | + $rs1 = & $conn->Execute($sql); |
|
708 | 708 | ADODB_Session::_dumprs($rs1); |
709 | 709 | if (!$rs1) { |
710 | 710 | $err = $conn->ErrorMsg()."\n"; |
711 | 711 | } |
712 | - $rs2 =& $conn->UpdateBlob($table, $data, $val, " sesskey=$qkey", strtoupper($clob)); |
|
712 | + $rs2 = & $conn->UpdateBlob($table, $data, $val, " sesskey=$qkey", strtoupper($clob)); |
|
713 | 713 | ADODB_Session::_dumprs($rs2); |
714 | 714 | if (!$rs2) { |
715 | 715 | $err .= $conn->ErrorMsg()."\n"; |
@@ -724,14 +724,14 @@ discard block |
||
724 | 724 | } |
725 | 725 | |
726 | 726 | if (!$rs) { |
727 | - ADOConnection::outp('<p>Session Replace: ' . $conn->ErrorMsg() . '</p>', false); |
|
727 | + ADOConnection::outp('<p>Session Replace: '.$conn->ErrorMsg().'</p>', false); |
|
728 | 728 | return false; |
729 | - } else { |
|
729 | + } else { |
|
730 | 730 | // bug in access driver (could be odbc?) means that info is not committed |
731 | 731 | // properly unless select statement executed in Win2000 |
732 | 732 | if ($conn->databaseType == 'access') { |
733 | 733 | $sql = "SELECT sesskey FROM $table WHERE $binary sesskey = $qkey"; |
734 | - $rs =& $conn->Execute($sql); |
|
734 | + $rs = & $conn->Execute($sql); |
|
735 | 735 | ADODB_Session::_dumprs($rs); |
736 | 736 | if ($rs) { |
737 | 737 | $rs->Close(); |
@@ -747,9 +747,9 @@ discard block |
||
747 | 747 | /*! |
748 | 748 | */ |
749 | 749 | function destroy($key) { |
750 | - $conn =& ADODB_Session::_conn(); |
|
751 | - $table = ADODB_Session::table(); |
|
752 | - $expire_notify = ADODB_Session::expireNotify(); |
|
750 | + $conn = & ADODB_Session::_conn(); |
|
751 | + $table = ADODB_Session::table(); |
|
752 | + $expire_notify = ADODB_Session::expireNotify(); |
|
753 | 753 | |
754 | 754 | if (!$conn) { |
755 | 755 | return false; |
@@ -765,7 +765,7 @@ discard block |
||
765 | 765 | $fn = next($expire_notify); |
766 | 766 | $savem = $conn->SetFetchMode(ADODB_FETCH_NUM); |
767 | 767 | $sql = "SELECT expireref, sesskey FROM $table WHERE $binary sesskey = $qkey"; |
768 | - $rs =& $conn->Execute($sql); |
|
768 | + $rs = & $conn->Execute($sql); |
|
769 | 769 | ADODB_Session::_dumprs($rs); |
770 | 770 | $conn->SetFetchMode($savem); |
771 | 771 | if (!$rs) { |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | } |
783 | 783 | |
784 | 784 | $sql = "DELETE FROM $table WHERE $binary sesskey = $qkey"; |
785 | - $rs =& $conn->Execute($sql); |
|
785 | + $rs = & $conn->Execute($sql); |
|
786 | 786 | ADODB_Session::_dumprs($rs); |
787 | 787 | if ($rs) { |
788 | 788 | $rs->Close(); |
@@ -794,12 +794,12 @@ discard block |
||
794 | 794 | /*! |
795 | 795 | */ |
796 | 796 | function gc($maxlifetime) { |
797 | - $conn =& ADODB_Session::_conn(); |
|
798 | - $debug = ADODB_Session::debug(); |
|
799 | - $expire_notify = ADODB_Session::expireNotify(); |
|
800 | - $optimize = ADODB_Session::optimize(); |
|
801 | - $sync_seconds = ADODB_Session::syncSeconds(); |
|
802 | - $table = ADODB_Session::table(); |
|
797 | + $conn = & ADODB_Session::_conn(); |
|
798 | + $debug = ADODB_Session::debug(); |
|
799 | + $expire_notify = ADODB_Session::expireNotify(); |
|
800 | + $optimize = ADODB_Session::optimize(); |
|
801 | + $sync_seconds = ADODB_Session::syncSeconds(); |
|
802 | + $table = ADODB_Session::table(); |
|
803 | 803 | |
804 | 804 | if (!$conn) { |
805 | 805 | return false; |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | $fn = next($expire_notify); |
817 | 817 | $savem = $conn->SetFetchMode(ADODB_FETCH_NUM); |
818 | 818 | $sql = "SELECT expireref, sesskey FROM $table WHERE expiry < $time"; |
819 | - $rs =& $conn->Execute($sql); |
|
819 | + $rs = & $conn->Execute($sql); |
|
820 | 820 | ADODB_Session::_dumprs($rs); |
821 | 821 | $conn->SetFetchMode($savem); |
822 | 822 | if ($rs) { |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | } |
836 | 836 | } else { |
837 | 837 | $sql = "DELETE FROM $table WHERE expiry < $time"; |
838 | - $rs =& $conn->Execute($sql); |
|
838 | + $rs = & $conn->Execute($sql); |
|
839 | 839 | ADODB_Session::_dumprs($rs); |
840 | 840 | if ($rs) { |
841 | 841 | $rs->Close(); |
@@ -869,7 +869,7 @@ discard block |
||
869 | 869 | } |
870 | 870 | $sql .= " FROM $table"; |
871 | 871 | |
872 | - $rs =& $conn->SelectLimit($sql, 1); |
|
872 | + $rs = & $conn->SelectLimit($sql, 1); |
|
873 | 873 | if ($rs && !$rs->EOF) { |
874 | 874 | $dbts = reset($rs->fields); |
875 | 875 | $rs->Close(); |
@@ -877,9 +877,9 @@ discard block |
||
877 | 877 | $t = time(); |
878 | 878 | |
879 | 879 | if (abs($dbt - $t) >= $sync_seconds) { |
880 | - $msg = __FILE__ . |
|
881 | - ": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: " . |
|
882 | - " database=$dbt ($dbts), webserver=$t (diff=". (abs($dbt - $t) / 60) . ' minutes)'; |
|
880 | + $msg = __FILE__. |
|
881 | + ": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: ". |
|
882 | + " database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt - $t) / 60).' minutes)'; |
|
883 | 883 | error_log($msg); |
884 | 884 | if ($debug) { |
885 | 885 | ADOConnection::outp("<p>$msg</p>"); |
@@ -25,11 +25,15 @@ discard block |
||
25 | 25 | |
26 | 26 | */ |
27 | 27 | |
28 | -if (!defined('_ADODB_LAYER')) { |
|
28 | +if (!defined('_ADODB_LAYER')) |
|
29 | +{ |
|
29 | 30 | require_once realpath(dirname(__FILE__) . '/../adodb.inc.php'); |
30 | 31 | } |
31 | 32 | |
32 | -if (defined('ADODB_SESSION')) return 1; |
|
33 | +if (defined('ADODB_SESSION')) |
|
34 | +{ |
|
35 | + return 1; |
|
36 | +} |
|
33 | 37 | |
34 | 38 | define('ADODB_SESSION', dirname(__FILE__)); |
35 | 39 | |
@@ -43,11 +47,12 @@ discard block |
||
43 | 47 | 3. After urldecode, run the serialized string through this function: |
44 | 48 | |
45 | 49 | */ |
46 | -function adodb_unserialize( $serialized_string ) |
|
50 | +function adodb_unserialize( $serialized_string ) |
|
47 | 51 | { |
48 | 52 | $variables = array( ); |
49 | 53 | $a = preg_split( "/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); |
50 | - for( $i = 0; $i < count( $a ); $i = $i+2 ) { |
|
54 | + for( $i = 0; $i < count( $a ); $i = $i+2 ) |
|
55 | + { |
|
51 | 56 | $variables[$a[$i]] = unserialize( $a[$i+1] ); |
52 | 57 | } |
53 | 58 | return( $variables ); |
@@ -57,15 +62,21 @@ discard block |
||
57 | 62 | Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1 |
58 | 63 | Since adodb 4.61. |
59 | 64 | */ |
60 | -function adodb_session_regenerate_id() |
|
65 | +function adodb_session_regenerate_id() |
|
61 | 66 | { |
62 | 67 | $conn =& ADODB_Session::_conn(); |
63 | - if (!$conn) return false; |
|
68 | + if (!$conn) |
|
69 | + { |
|
70 | + return false; |
|
71 | + } |
|
64 | 72 | |
65 | 73 | $old_id = session_id(); |
66 | - if (function_exists('session_regenerate_id')) { |
|
74 | + if (function_exists('session_regenerate_id')) |
|
75 | + { |
|
67 | 76 | session_regenerate_id(); |
68 | - } else { |
|
77 | + } |
|
78 | + else |
|
79 | + { |
|
69 | 80 | session_id(md5(uniqid(rand(), true))); |
70 | 81 | $ck = session_get_cookie_params(); |
71 | 82 | setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); |
@@ -75,9 +86,13 @@ discard block |
||
75 | 86 | $ok =& $conn->Execute('UPDATE '. ADODB_Session::table(). ' SET sesskey='. $conn->qstr($new_id). ' WHERE sesskey='.$conn->qstr($old_id)); |
76 | 87 | |
77 | 88 | /* it is possible that the update statement fails due to a collision */ |
78 | - if (!$ok) { |
|
89 | + if (!$ok) |
|
90 | + { |
|
79 | 91 | session_id($old_id); |
80 | - if (empty($ck)) $ck = session_get_cookie_params(); |
|
92 | + if (empty($ck)) |
|
93 | + { |
|
94 | + $ck = session_get_cookie_params(); |
|
95 | + } |
|
81 | 96 | setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); |
82 | 97 | return false; |
83 | 98 | } |
@@ -94,10 +109,19 @@ discard block |
||
94 | 109 | function adodb_session_create_table($schemaFile=null,$conn = null) |
95 | 110 | { |
96 | 111 | // set default values |
97 | - if ($schemaFile===null) $schemaFile = ADODB_SESSION . '/session_schema.xml'; |
|
98 | - if ($conn===null) $conn =& ADODB_Session::_conn(); |
|
99 | - |
|
100 | - if (!$conn) return 0; |
|
112 | + if ($schemaFile===null) |
|
113 | + { |
|
114 | + $schemaFile = ADODB_SESSION . '/session_schema.xml'; |
|
115 | + } |
|
116 | + if ($conn===null) |
|
117 | + { |
|
118 | + $conn =& ADODB_Session::_conn(); |
|
119 | + } |
|
120 | + |
|
121 | + if (!$conn) |
|
122 | + { |
|
123 | + return 0; |
|
124 | + } |
|
101 | 125 | |
102 | 126 | $schema = new adoSchema($conn); |
103 | 127 | $schema->ParseSchema($schemaFile); |
@@ -107,7 +131,8 @@ discard block |
||
107 | 131 | /*! |
108 | 132 | \static |
109 | 133 | */ |
110 | -class ADODB_Session { |
|
134 | +class ADODB_Session |
|
135 | +{ |
|
111 | 136 | ///////////////////// |
112 | 137 | // getter/setter methods |
113 | 138 | ///////////////////// |
@@ -124,16 +149,21 @@ discard block |
||
124 | 149 | */ |
125 | 150 | /*! |
126 | 151 | */ |
127 | - function driver($driver = null) { |
|
152 | + function driver($driver = null) |
|
153 | + { |
|
128 | 154 | static $_driver = 'mysql'; |
129 | 155 | static $set = false; |
130 | 156 | |
131 | - if (!is_null($driver)) { |
|
157 | + if (!is_null($driver)) |
|
158 | + { |
|
132 | 159 | $_driver = trim($driver); |
133 | 160 | $set = true; |
134 | - } elseif (!$set) { |
|
161 | + } |
|
162 | + elseif (!$set) |
|
163 | + { |
|
135 | 164 | // backwards compatibility |
136 | - if (isset($GLOBALS['ADODB_SESSION_DRIVER'])) { |
|
165 | + if (isset($GLOBALS['ADODB_SESSION_DRIVER'])) |
|
166 | + { |
|
137 | 167 | return $GLOBALS['ADODB_SESSION_DRIVER']; |
138 | 168 | } |
139 | 169 | } |
@@ -143,16 +173,21 @@ discard block |
||
143 | 173 | |
144 | 174 | /*! |
145 | 175 | */ |
146 | - function host($host = null) { |
|
176 | + function host($host = null) |
|
177 | + { |
|
147 | 178 | static $_host = 'localhost'; |
148 | 179 | static $set = false; |
149 | 180 | |
150 | - if (!is_null($host)) { |
|
181 | + if (!is_null($host)) |
|
182 | + { |
|
151 | 183 | $_host = trim($host); |
152 | 184 | $set = true; |
153 | - } elseif (!$set) { |
|
185 | + } |
|
186 | + elseif (!$set) |
|
187 | + { |
|
154 | 188 | // backwards compatibility |
155 | - if (isset($GLOBALS['ADODB_SESSION_CONNECT'])) { |
|
189 | + if (isset($GLOBALS['ADODB_SESSION_CONNECT'])) |
|
190 | + { |
|
156 | 191 | return $GLOBALS['ADODB_SESSION_CONNECT']; |
157 | 192 | } |
158 | 193 | } |
@@ -162,16 +197,21 @@ discard block |
||
162 | 197 | |
163 | 198 | /*! |
164 | 199 | */ |
165 | - function user($user = null) { |
|
200 | + function user($user = null) |
|
201 | + { |
|
166 | 202 | static $_user = 'root'; |
167 | 203 | static $set = false; |
168 | 204 | |
169 | - if (!is_null($user)) { |
|
205 | + if (!is_null($user)) |
|
206 | + { |
|
170 | 207 | $_user = trim($user); |
171 | 208 | $set = true; |
172 | - } elseif (!$set) { |
|
209 | + } |
|
210 | + elseif (!$set) |
|
211 | + { |
|
173 | 212 | // backwards compatibility |
174 | - if (isset($GLOBALS['ADODB_SESSION_USER'])) { |
|
213 | + if (isset($GLOBALS['ADODB_SESSION_USER'])) |
|
214 | + { |
|
175 | 215 | return $GLOBALS['ADODB_SESSION_USER']; |
176 | 216 | } |
177 | 217 | } |
@@ -181,16 +221,21 @@ discard block |
||
181 | 221 | |
182 | 222 | /*! |
183 | 223 | */ |
184 | - function password($password = null) { |
|
224 | + function password($password = null) |
|
225 | + { |
|
185 | 226 | static $_password = ''; |
186 | 227 | static $set = false; |
187 | 228 | |
188 | - if (!is_null($password)) { |
|
229 | + if (!is_null($password)) |
|
230 | + { |
|
189 | 231 | $_password = $password; |
190 | 232 | $set = true; |
191 | - } elseif (!$set) { |
|
233 | + } |
|
234 | + elseif (!$set) |
|
235 | + { |
|
192 | 236 | // backwards compatibility |
193 | - if (isset($GLOBALS['ADODB_SESSION_PWD'])) { |
|
237 | + if (isset($GLOBALS['ADODB_SESSION_PWD'])) |
|
238 | + { |
|
194 | 239 | return $GLOBALS['ADODB_SESSION_PWD']; |
195 | 240 | } |
196 | 241 | } |
@@ -200,16 +245,21 @@ discard block |
||
200 | 245 | |
201 | 246 | /*! |
202 | 247 | */ |
203 | - function database($database = null) { |
|
248 | + function database($database = null) |
|
249 | + { |
|
204 | 250 | static $_database = 'xphplens_2'; |
205 | 251 | static $set = false; |
206 | 252 | |
207 | - if (!is_null($database)) { |
|
253 | + if (!is_null($database)) |
|
254 | + { |
|
208 | 255 | $_database = trim($database); |
209 | 256 | $set = true; |
210 | - } elseif (!$set) { |
|
257 | + } |
|
258 | + elseif (!$set) |
|
259 | + { |
|
211 | 260 | // backwards compatibility |
212 | - if (isset($GLOBALS['ADODB_SESSION_DB'])) { |
|
261 | + if (isset($GLOBALS['ADODB_SESSION_DB'])) |
|
262 | + { |
|
213 | 263 | return $GLOBALS['ADODB_SESSION_DB']; |
214 | 264 | } |
215 | 265 | } |
@@ -219,11 +269,12 @@ discard block |
||
219 | 269 | |
220 | 270 | /*! |
221 | 271 | */ |
222 | - function persist($persist = null) |
|
272 | + function persist($persist = null) |
|
223 | 273 | { |
224 | 274 | static $_persist = true; |
225 | 275 | |
226 | - if (!is_null($persist)) { |
|
276 | + if (!is_null($persist)) |
|
277 | + { |
|
227 | 278 | $_persist = trim($persist); |
228 | 279 | } |
229 | 280 | |
@@ -232,22 +283,29 @@ discard block |
||
232 | 283 | |
233 | 284 | /*! |
234 | 285 | */ |
235 | - function lifetime($lifetime = null) { |
|
286 | + function lifetime($lifetime = null) |
|
287 | + { |
|
236 | 288 | static $_lifetime; |
237 | 289 | static $set = false; |
238 | 290 | |
239 | - if (!is_null($lifetime)) { |
|
291 | + if (!is_null($lifetime)) |
|
292 | + { |
|
240 | 293 | $_lifetime = (int) $lifetime; |
241 | 294 | $set = true; |
242 | - } elseif (!$set) { |
|
295 | + } |
|
296 | + elseif (!$set) |
|
297 | + { |
|
243 | 298 | // backwards compatibility |
244 | - if (isset($GLOBALS['ADODB_SESS_LIFE'])) { |
|
299 | + if (isset($GLOBALS['ADODB_SESS_LIFE'])) |
|
300 | + { |
|
245 | 301 | return $GLOBALS['ADODB_SESS_LIFE']; |
246 | 302 | } |
247 | 303 | } |
248 | - if (!$_lifetime) { |
|
304 | + if (!$_lifetime) |
|
305 | + { |
|
249 | 306 | $_lifetime = ini_get('session.gc_maxlifetime'); |
250 | - if ($_lifetime <= 1) { |
|
307 | + if ($_lifetime <= 1) |
|
308 | + { |
|
251 | 309 | // bug in PHP 4.0.3 pl 1 -- how about other versions? |
252 | 310 | //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $lifetime</h3>"; |
253 | 311 | $_lifetime = 1440; |
@@ -259,21 +317,27 @@ discard block |
||
259 | 317 | |
260 | 318 | /*! |
261 | 319 | */ |
262 | - function debug($debug = null) { |
|
320 | + function debug($debug = null) |
|
321 | + { |
|
263 | 322 | static $_debug = false; |
264 | 323 | static $set = false; |
265 | 324 | |
266 | - if (!is_null($debug)) { |
|
325 | + if (!is_null($debug)) |
|
326 | + { |
|
267 | 327 | $_debug = (bool) $debug; |
268 | 328 | |
269 | 329 | $conn = ADODB_Session::_conn(); |
270 | - if ($conn) { |
|
330 | + if ($conn) |
|
331 | + { |
|
271 | 332 | $conn->debug = $_debug; |
272 | 333 | } |
273 | 334 | $set = true; |
274 | - } elseif (!$set) { |
|
335 | + } |
|
336 | + elseif (!$set) |
|
337 | + { |
|
275 | 338 | // backwards compatibility |
276 | - if (isset($GLOBALS['ADODB_SESS_DEBUG'])) { |
|
339 | + if (isset($GLOBALS['ADODB_SESS_DEBUG'])) |
|
340 | + { |
|
277 | 341 | return $GLOBALS['ADODB_SESS_DEBUG']; |
278 | 342 | } |
279 | 343 | } |
@@ -283,16 +347,21 @@ discard block |
||
283 | 347 | |
284 | 348 | /*! |
285 | 349 | */ |
286 | - function expireNotify($expire_notify = null) { |
|
350 | + function expireNotify($expire_notify = null) |
|
351 | + { |
|
287 | 352 | static $_expire_notify; |
288 | 353 | static $set = false; |
289 | 354 | |
290 | - if (!is_null($expire_notify)) { |
|
355 | + if (!is_null($expire_notify)) |
|
356 | + { |
|
291 | 357 | $_expire_notify = $expire_notify; |
292 | 358 | $set = true; |
293 | - } elseif (!$set) { |
|
359 | + } |
|
360 | + elseif (!$set) |
|
361 | + { |
|
294 | 362 | // backwards compatibility |
295 | - if (isset($GLOBALS['ADODB_SESSION_EXPIRE_NOTIFY'])) { |
|
363 | + if (isset($GLOBALS['ADODB_SESSION_EXPIRE_NOTIFY'])) |
|
364 | + { |
|
296 | 365 | return $GLOBALS['ADODB_SESSION_EXPIRE_NOTIFY']; |
297 | 366 | } |
298 | 367 | } |
@@ -302,16 +371,21 @@ discard block |
||
302 | 371 | |
303 | 372 | /*! |
304 | 373 | */ |
305 | - function table($table = null) { |
|
374 | + function table($table = null) |
|
375 | + { |
|
306 | 376 | static $_table = 'sessions'; |
307 | 377 | static $set = false; |
308 | 378 | |
309 | - if (!is_null($table)) { |
|
379 | + if (!is_null($table)) |
|
380 | + { |
|
310 | 381 | $_table = trim($table); |
311 | 382 | $set = true; |
312 | - } elseif (!$set) { |
|
383 | + } |
|
384 | + elseif (!$set) |
|
385 | + { |
|
313 | 386 | // backwards compatibility |
314 | - if (isset($GLOBALS['ADODB_SESSION_TBL'])) { |
|
387 | + if (isset($GLOBALS['ADODB_SESSION_TBL'])) |
|
388 | + { |
|
315 | 389 | return $GLOBALS['ADODB_SESSION_TBL']; |
316 | 390 | } |
317 | 391 | } |
@@ -321,16 +395,21 @@ discard block |
||
321 | 395 | |
322 | 396 | /*! |
323 | 397 | */ |
324 | - function optimize($optimize = null) { |
|
398 | + function optimize($optimize = null) |
|
399 | + { |
|
325 | 400 | static $_optimize = false; |
326 | 401 | static $set = false; |
327 | 402 | |
328 | - if (!is_null($optimize)) { |
|
403 | + if (!is_null($optimize)) |
|
404 | + { |
|
329 | 405 | $_optimize = (bool) $optimize; |
330 | 406 | $set = true; |
331 | - } elseif (!$set) { |
|
407 | + } |
|
408 | + elseif (!$set) |
|
409 | + { |
|
332 | 410 | // backwards compatibility |
333 | - if (defined('ADODB_SESSION_OPTIMIZE')) { |
|
411 | + if (defined('ADODB_SESSION_OPTIMIZE')) |
|
412 | + { |
|
334 | 413 | return true; |
335 | 414 | } |
336 | 415 | } |
@@ -340,16 +419,21 @@ discard block |
||
340 | 419 | |
341 | 420 | /*! |
342 | 421 | */ |
343 | - function syncSeconds($sync_seconds = null) { |
|
422 | + function syncSeconds($sync_seconds = null) |
|
423 | + { |
|
344 | 424 | static $_sync_seconds = 60; |
345 | 425 | static $set = false; |
346 | 426 | |
347 | - if (!is_null($sync_seconds)) { |
|
427 | + if (!is_null($sync_seconds)) |
|
428 | + { |
|
348 | 429 | $_sync_seconds = (int) $sync_seconds; |
349 | 430 | $set = true; |
350 | - } elseif (!$set) { |
|
431 | + } |
|
432 | + elseif (!$set) |
|
433 | + { |
|
351 | 434 | // backwards compatibility |
352 | - if (defined('ADODB_SESSION_SYNCH_SECS')) { |
|
435 | + if (defined('ADODB_SESSION_SYNCH_SECS')) |
|
436 | + { |
|
353 | 437 | return ADODB_SESSION_SYNCH_SECS; |
354 | 438 | } |
355 | 439 | } |
@@ -359,16 +443,21 @@ discard block |
||
359 | 443 | |
360 | 444 | /*! |
361 | 445 | */ |
362 | - function clob($clob = null) { |
|
446 | + function clob($clob = null) |
|
447 | + { |
|
363 | 448 | static $_clob = false; |
364 | 449 | static $set = false; |
365 | 450 | |
366 | - if (!is_null($clob)) { |
|
451 | + if (!is_null($clob)) |
|
452 | + { |
|
367 | 453 | $_clob = strtolower(trim($clob)); |
368 | 454 | $set = true; |
369 | - } elseif (!$set) { |
|
455 | + } |
|
456 | + elseif (!$set) |
|
457 | + { |
|
370 | 458 | // backwards compatibility |
371 | - if (isset($GLOBALS['ADODB_SESSION_USE_LOBS'])) { |
|
459 | + if (isset($GLOBALS['ADODB_SESSION_USE_LOBS'])) |
|
460 | + { |
|
372 | 461 | return $GLOBALS['ADODB_SESSION_USE_LOBS']; |
373 | 462 | } |
374 | 463 | } |
@@ -378,10 +467,12 @@ discard block |
||
378 | 467 | |
379 | 468 | /*! |
380 | 469 | */ |
381 | - function dataFieldName($data_field_name = null) { |
|
470 | + function dataFieldName($data_field_name = null) |
|
471 | + { |
|
382 | 472 | static $_data_field_name = 'data'; |
383 | 473 | |
384 | - if (!is_null($data_field_name)) { |
|
474 | + if (!is_null($data_field_name)) |
|
475 | + { |
|
385 | 476 | $_data_field_name = trim($data_field_name); |
386 | 477 | } |
387 | 478 | |
@@ -390,11 +481,14 @@ discard block |
||
390 | 481 | |
391 | 482 | /*! |
392 | 483 | */ |
393 | - function filter($filter = null) { |
|
484 | + function filter($filter = null) |
|
485 | + { |
|
394 | 486 | static $_filter = array(); |
395 | 487 | |
396 | - if (!is_null($filter)) { |
|
397 | - if (!is_array($filter)) { |
|
488 | + if (!is_null($filter)) |
|
489 | + { |
|
490 | + if (!is_array($filter)) |
|
491 | + { |
|
398 | 492 | $filter = array($filter); |
399 | 493 | } |
400 | 494 | $_filter = $filter; |
@@ -405,10 +499,12 @@ discard block |
||
405 | 499 | |
406 | 500 | /*! |
407 | 501 | */ |
408 | - function encryptionKey($encryption_key = null) { |
|
502 | + function encryptionKey($encryption_key = null) |
|
503 | + { |
|
409 | 504 | static $_encryption_key = 'CRYPTED ADODB SESSIONS ROCK!'; |
410 | 505 | |
411 | - if (!is_null($encryption_key)) { |
|
506 | + if (!is_null($encryption_key)) |
|
507 | + { |
|
412 | 508 | $_encryption_key = $encryption_key; |
413 | 509 | } |
414 | 510 | |
@@ -427,10 +523,12 @@ discard block |
||
427 | 523 | |
428 | 524 | /*! |
429 | 525 | */ |
430 | - function _crc($crc = null) { |
|
526 | + function _crc($crc = null) |
|
527 | + { |
|
431 | 528 | static $_crc = false; |
432 | 529 | |
433 | - if (!is_null($crc)) { |
|
530 | + if (!is_null($crc)) |
|
531 | + { |
|
434 | 532 | $_crc = $crc; |
435 | 533 | } |
436 | 534 | |
@@ -439,7 +537,8 @@ discard block |
||
439 | 537 | |
440 | 538 | /*! |
441 | 539 | */ |
442 | - function _init() { |
|
540 | + function _init() |
|
541 | + { |
|
443 | 542 | session_module_name('user'); |
444 | 543 | session_set_save_handler( |
445 | 544 | array('ADODB_Session', 'open'), |
@@ -454,7 +553,8 @@ discard block |
||
454 | 553 | |
455 | 554 | /*! |
456 | 555 | */ |
457 | - function _sessionKey() { |
|
556 | + function _sessionKey() |
|
557 | + { |
|
458 | 558 | // use this function to create the encryption key for crypted sessions |
459 | 559 | // crypt the used key, ADODB_Session::encryptionKey() as key and session_id() as salt |
460 | 560 | return crypt(ADODB_Session::encryptionKey(), session_id()); |
@@ -462,26 +562,31 @@ discard block |
||
462 | 562 | |
463 | 563 | /*! |
464 | 564 | */ |
465 | - function _dumprs($rs) { |
|
565 | + function _dumprs($rs) |
|
566 | + { |
|
466 | 567 | $conn =& ADODB_Session::_conn(); |
467 | 568 | $debug = ADODB_Session::debug(); |
468 | 569 | |
469 | - if (!$conn) { |
|
570 | + if (!$conn) |
|
571 | + { |
|
470 | 572 | return; |
471 | 573 | } |
472 | 574 | |
473 | - if (!$debug) { |
|
575 | + if (!$debug) |
|
576 | + { |
|
474 | 577 | return; |
475 | 578 | } |
476 | 579 | |
477 | - if (!$rs) { |
|
580 | + if (!$rs) |
|
581 | + { |
|
478 | 582 | echo "<br />\$rs is null or false<br />\n"; |
479 | 583 | return; |
480 | 584 | } |
481 | 585 | |
482 | 586 | //echo "<br />\nAffected_Rows=",$conn->Affected_Rows(),"<br />\n"; |
483 | 587 | |
484 | - if (!is_object($rs)) { |
|
588 | + if (!is_object($rs)) |
|
589 | + { |
|
485 | 590 | return; |
486 | 591 | } |
487 | 592 | |
@@ -498,10 +603,12 @@ discard block |
||
498 | 603 | |
499 | 604 | If $conn already exists, reuse that connection |
500 | 605 | */ |
501 | - function open($save_path, $session_name, $persist = null) { |
|
606 | + function open($save_path, $session_name, $persist = null) |
|
607 | + { |
|
502 | 608 | $conn =& ADODB_Session::_conn(); |
503 | 609 | |
504 | - if ($conn) { |
|
610 | + if ($conn) |
|
611 | + { |
|
505 | 612 | return true; |
506 | 613 | } |
507 | 614 | |
@@ -512,9 +619,12 @@ discard block |
||
512 | 619 | $password = ADODB_Session::password(); |
513 | 620 | $user = ADODB_Session::user(); |
514 | 621 | |
515 | - if (!is_null($persist)) { |
|
622 | + if (!is_null($persist)) |
|
623 | + { |
|
516 | 624 | ADODB_Session::persist($persist); |
517 | - } else { |
|
625 | + } |
|
626 | + else |
|
627 | + { |
|
518 | 628 | $persist = ADODB_Session::persist(); |
519 | 629 | } |
520 | 630 | |
@@ -526,25 +636,34 @@ discard block |
||
526 | 636 | // cannot use =& below - do not know why... |
527 | 637 | $conn =& ADONewConnection($driver); |
528 | 638 | |
529 | - if ($debug) { |
|
639 | + if ($debug) |
|
640 | + { |
|
530 | 641 | $conn->debug = true; |
531 | 642 | // ADOConnection::outp( " driver=$driver user=$user pwd=$password db=$database "); |
532 | 643 | } |
533 | 644 | |
534 | - if ($persist) { |
|
535 | - switch($persist) { |
|
645 | + if ($persist) |
|
646 | + { |
|
647 | + switch($persist) |
|
648 | + { |
|
536 | 649 | default: |
537 | 650 | case 'P': $ok = $conn->PConnect($host, $user, $password, $database); break; |
538 | 651 | case 'C': $ok = $conn->Connect($host, $user, $password, $database); break; |
539 | 652 | case 'N': $ok = $conn->NConnect($host, $user, $password, $database); break; |
540 | 653 | } |
541 | - } else { |
|
654 | + } |
|
655 | + else |
|
656 | + { |
|
542 | 657 | $ok = $conn->Connect($host, $user, $password, $database); |
543 | 658 | } |
544 | 659 | |
545 | - if ($ok) $GLOBALS['ADODB_SESS_CONN'] =& $conn; |
|
546 | - else |
|
547 | - ADOConnection::outp('<p>Session: connection failed</p>', false); |
|
660 | + if ($ok) |
|
661 | + { |
|
662 | + $GLOBALS['ADODB_SESS_CONN'] =& $conn; |
|
663 | + } |
|
664 | + else { |
|
665 | + ADOConnection::outp('<p>Session: connection failed</p>', false); |
|
666 | + } |
|
548 | 667 | |
549 | 668 | |
550 | 669 | return $ok; |
@@ -553,7 +672,8 @@ discard block |
||
553 | 672 | /*! |
554 | 673 | Close the connection |
555 | 674 | */ |
556 | - function close() { |
|
675 | + function close() |
|
676 | + { |
|
557 | 677 | /* |
558 | 678 | $conn =& ADODB_Session::_conn(); |
559 | 679 | if ($conn) $conn->Close(); |
@@ -564,13 +684,15 @@ discard block |
||
564 | 684 | /* |
565 | 685 | Slurp in the session variables and return the serialized string |
566 | 686 | */ |
567 | - function read($key) { |
|
687 | + function read($key) |
|
688 | + { |
|
568 | 689 | $conn =& ADODB_Session::_conn(); |
569 | 690 | $data = ADODB_Session::dataFieldName(); |
570 | 691 | $filter = ADODB_Session::filter(); |
571 | 692 | $table = ADODB_Session::table(); |
572 | 693 | |
573 | - if (!$conn) { |
|
694 | + if (!$conn) |
|
695 | + { |
|
574 | 696 | return ''; |
575 | 697 | } |
576 | 698 | |
@@ -589,14 +711,20 @@ discard block |
||
589 | 711 | |
590 | 712 | $rs =& $conn->Execute($sql); |
591 | 713 | //ADODB_Session::_dumprs($rs); |
592 | - if ($rs) { |
|
593 | - if ($rs->EOF) { |
|
714 | + if ($rs) |
|
715 | + { |
|
716 | + if ($rs->EOF) |
|
717 | + { |
|
594 | 718 | $v = ''; |
595 | - } else { |
|
719 | + } |
|
720 | + else |
|
721 | + { |
|
596 | 722 | $v = reset($rs->fields); |
597 | 723 | $filter = array_reverse($filter); |
598 | - foreach ($filter as $f) { |
|
599 | - if (is_object($f)) { |
|
724 | + foreach ($filter as $f) |
|
725 | + { |
|
726 | + if (is_object($f)) |
|
727 | + { |
|
600 | 728 | $v = $f->read($v, ADODB_Session::_sessionKey()); |
601 | 729 | } |
602 | 730 | } |
@@ -617,7 +745,8 @@ discard block |
||
617 | 745 | |
618 | 746 | If the data has not been modified since the last read(), we do not write. |
619 | 747 | */ |
620 | - function write($key, $val) { |
|
748 | + function write($key, $val) |
|
749 | + { |
|
621 | 750 | $clob = ADODB_Session::clob(); |
622 | 751 | $conn =& ADODB_Session::_conn(); |
623 | 752 | $crc = ADODB_Session::_crc(); |
@@ -629,7 +758,8 @@ discard block |
||
629 | 758 | $lifetime = ADODB_Session::lifetime(); |
630 | 759 | $table = ADODB_Session::table(); |
631 | 760 | |
632 | - if (!$conn) { |
|
761 | + if (!$conn) |
|
762 | + { |
|
633 | 763 | return false; |
634 | 764 | } |
635 | 765 | $qkey = $conn->qstr($key); |
@@ -642,41 +772,53 @@ discard block |
||
642 | 772 | |
643 | 773 | // crc32 optimization since adodb 2.1 |
644 | 774 | // now we only update expiry date, thx to sebastian thom in adodb 2.32 |
645 | - if ($crc !== false && $crc == (strlen($val) . crc32($val))) { |
|
646 | - if ($debug) { |
|
775 | + if ($crc !== false && $crc == (strlen($val) . crc32($val))) |
|
776 | + { |
|
777 | + if ($debug) |
|
778 | + { |
|
647 | 779 | echo '<p>Session: Only updating date - crc32 not changed</p>'; |
648 | 780 | } |
649 | 781 | $sql = "UPDATE $table SET expiry = ".$conn->Param('0')." WHERE $binary sesskey = ".$conn->Param('1')." AND expiry >= ".$conn->Param('2'); |
650 | 782 | $rs =& $conn->Execute($sql,array($expiry,$key,time())); |
651 | 783 | ADODB_Session::_dumprs($rs); |
652 | - if ($rs) { |
|
784 | + if ($rs) |
|
785 | + { |
|
653 | 786 | $rs->Close(); |
654 | 787 | } |
655 | 788 | return true; |
656 | 789 | } |
657 | 790 | $val = rawurlencode($val); |
658 | - foreach ($filter as $f) { |
|
659 | - if (is_object($f)) { |
|
791 | + foreach ($filter as $f) |
|
792 | + { |
|
793 | + if (is_object($f)) |
|
794 | + { |
|
660 | 795 | $val = $f->write($val, ADODB_Session::_sessionKey()); |
661 | 796 | } |
662 | 797 | } |
663 | 798 | |
664 | 799 | $arr = array('sesskey' => $key, 'expiry' => $expiry, $data => $val, 'expireref' => ''); |
665 | - if ($expire_notify) { |
|
800 | + if ($expire_notify) |
|
801 | + { |
|
666 | 802 | $var = reset($expire_notify); |
667 | 803 | global $$var; |
668 | - if (isset($$var)) { |
|
804 | + if (isset($$var)) |
|
805 | + { |
|
669 | 806 | $arr['expireref'] = $$var; |
670 | 807 | } |
671 | 808 | } |
672 | 809 | |
673 | - if (!$clob) { // no lobs, simply use replace() |
|
810 | + if (!$clob) |
|
811 | + { |
|
812 | +// no lobs, simply use replace() |
|
674 | 813 | $arr[$data] = $conn->qstr($val); |
675 | 814 | $rs = $conn->Replace($table, $arr, 'sesskey', $autoQuote = true); |
676 | 815 | ADODB_Session::_dumprs($rs); |
677 | - } else { |
|
816 | + } |
|
817 | + else |
|
818 | + { |
|
678 | 819 | // what value shall we insert/update for lob row? |
679 | - switch ($driver) { |
|
820 | + switch ($driver) |
|
821 | + { |
|
680 | 822 | // empty_clob or empty_lob for oracle dbs |
681 | 823 | case 'oracle': |
682 | 824 | case 'oci8': |
@@ -694,46 +836,59 @@ discard block |
||
694 | 836 | // do we insert or update? => as for sesskey |
695 | 837 | $rs =& $conn->Execute("SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = $qkey"); |
696 | 838 | ADODB_Session::_dumprs($rs); |
697 | - if ($rs && reset($rs->fields) > 0) { |
|
839 | + if ($rs && reset($rs->fields) > 0) |
|
840 | + { |
|
698 | 841 | $sql = "UPDATE $table SET expiry = $expiry, $data = $lob_value WHERE sesskey = $qkey"; |
699 | - } else { |
|
842 | + } |
|
843 | + else |
|
844 | + { |
|
700 | 845 | $sql = "INSERT INTO $table (expiry, $data, sesskey) VALUES ($expiry, $lob_value, $qkey)"; |
701 | 846 | } |
702 | - if ($rs) { |
|
847 | + if ($rs) |
|
848 | + { |
|
703 | 849 | $rs->Close(); |
704 | 850 | } |
705 | 851 | |
706 | 852 | $err = ''; |
707 | 853 | $rs1 =& $conn->Execute($sql); |
708 | 854 | ADODB_Session::_dumprs($rs1); |
709 | - if (!$rs1) { |
|
855 | + if (!$rs1) |
|
856 | + { |
|
710 | 857 | $err = $conn->ErrorMsg()."\n"; |
711 | 858 | } |
712 | 859 | $rs2 =& $conn->UpdateBlob($table, $data, $val, " sesskey=$qkey", strtoupper($clob)); |
713 | 860 | ADODB_Session::_dumprs($rs2); |
714 | - if (!$rs2) { |
|
861 | + if (!$rs2) |
|
862 | + { |
|
715 | 863 | $err .= $conn->ErrorMsg()."\n"; |
716 | 864 | } |
717 | 865 | $rs = ($rs && $rs2) ? true : false; |
718 | - if ($rs1) { |
|
866 | + if ($rs1) |
|
867 | + { |
|
719 | 868 | $rs1->Close(); |
720 | 869 | } |
721 | - if (is_object($rs2)) { |
|
870 | + if (is_object($rs2)) |
|
871 | + { |
|
722 | 872 | $rs2->Close(); |
723 | 873 | } |
724 | 874 | } |
725 | 875 | |
726 | - if (!$rs) { |
|
876 | + if (!$rs) |
|
877 | + { |
|
727 | 878 | ADOConnection::outp('<p>Session Replace: ' . $conn->ErrorMsg() . '</p>', false); |
728 | 879 | return false; |
729 | - } else { |
|
880 | + } |
|
881 | + else |
|
882 | + { |
|
730 | 883 | // bug in access driver (could be odbc?) means that info is not committed |
731 | 884 | // properly unless select statement executed in Win2000 |
732 | - if ($conn->databaseType == 'access') { |
|
885 | + if ($conn->databaseType == 'access') |
|
886 | + { |
|
733 | 887 | $sql = "SELECT sesskey FROM $table WHERE $binary sesskey = $qkey"; |
734 | 888 | $rs =& $conn->Execute($sql); |
735 | 889 | ADODB_Session::_dumprs($rs); |
736 | - if ($rs) { |
|
890 | + if ($rs) |
|
891 | + { |
|
737 | 892 | $rs->Close(); |
738 | 893 | } |
739 | 894 | } |
@@ -746,12 +901,14 @@ discard block |
||
746 | 901 | |
747 | 902 | /*! |
748 | 903 | */ |
749 | - function destroy($key) { |
|
904 | + function destroy($key) |
|
905 | + { |
|
750 | 906 | $conn =& ADODB_Session::_conn(); |
751 | 907 | $table = ADODB_Session::table(); |
752 | 908 | $expire_notify = ADODB_Session::expireNotify(); |
753 | 909 | |
754 | - if (!$conn) { |
|
910 | + if (!$conn) |
|
911 | + { |
|
755 | 912 | return false; |
756 | 913 | } |
757 | 914 | |
@@ -760,7 +917,8 @@ discard block |
||
760 | 917 | $qkey = $conn->quote($key); |
761 | 918 | $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : ''; |
762 | 919 | |
763 | - if ($expire_notify) { |
|
920 | + if ($expire_notify) |
|
921 | + { |
|
764 | 922 | reset($expire_notify); |
765 | 923 | $fn = next($expire_notify); |
766 | 924 | $savem = $conn->SetFetchMode(ADODB_FETCH_NUM); |
@@ -768,10 +926,12 @@ discard block |
||
768 | 926 | $rs =& $conn->Execute($sql); |
769 | 927 | ADODB_Session::_dumprs($rs); |
770 | 928 | $conn->SetFetchMode($savem); |
771 | - if (!$rs) { |
|
929 | + if (!$rs) |
|
930 | + { |
|
772 | 931 | return false; |
773 | 932 | } |
774 | - if (!$rs->EOF) { |
|
933 | + if (!$rs->EOF) |
|
934 | + { |
|
775 | 935 | $ref = $rs->fields[0]; |
776 | 936 | $key = $rs->fields[1]; |
777 | 937 | //assert('$ref'); |
@@ -784,7 +944,8 @@ discard block |
||
784 | 944 | $sql = "DELETE FROM $table WHERE $binary sesskey = $qkey"; |
785 | 945 | $rs =& $conn->Execute($sql); |
786 | 946 | ADODB_Session::_dumprs($rs); |
787 | - if ($rs) { |
|
947 | + if ($rs) |
|
948 | + { |
|
788 | 949 | $rs->Close(); |
789 | 950 | } |
790 | 951 | |
@@ -793,7 +954,8 @@ discard block |
||
793 | 954 | |
794 | 955 | /*! |
795 | 956 | */ |
796 | - function gc($maxlifetime) { |
|
957 | + function gc($maxlifetime) |
|
958 | + { |
|
797 | 959 | $conn =& ADODB_Session::_conn(); |
798 | 960 | $debug = ADODB_Session::debug(); |
799 | 961 | $expire_notify = ADODB_Session::expireNotify(); |
@@ -801,7 +963,8 @@ discard block |
||
801 | 963 | $sync_seconds = ADODB_Session::syncSeconds(); |
802 | 964 | $table = ADODB_Session::table(); |
803 | 965 | |
804 | - if (!$conn) { |
|
966 | + if (!$conn) |
|
967 | + { |
|
805 | 968 | return false; |
806 | 969 | } |
807 | 970 | |
@@ -811,7 +974,8 @@ discard block |
||
811 | 974 | |
812 | 975 | $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : ''; |
813 | 976 | |
814 | - if ($expire_notify) { |
|
977 | + if ($expire_notify) |
|
978 | + { |
|
815 | 979 | reset($expire_notify); |
816 | 980 | $fn = next($expire_notify); |
817 | 981 | $savem = $conn->SetFetchMode(ADODB_FETCH_NUM); |
@@ -819,10 +983,12 @@ discard block |
||
819 | 983 | $rs =& $conn->Execute($sql); |
820 | 984 | ADODB_Session::_dumprs($rs); |
821 | 985 | $conn->SetFetchMode($savem); |
822 | - if ($rs) { |
|
986 | + if ($rs) |
|
987 | + { |
|
823 | 988 | $conn->BeginTrans(); |
824 | 989 | $keys = array(); |
825 | - while (!$rs->EOF) { |
|
990 | + while (!$rs->EOF) |
|
991 | + { |
|
826 | 992 | $ref = $rs->fields[0]; |
827 | 993 | $key = $rs->fields[1]; |
828 | 994 | $fn($ref, $key); |
@@ -833,55 +999,70 @@ discard block |
||
833 | 999 | |
834 | 1000 | $conn->CommitTrans(); |
835 | 1001 | } |
836 | - } else { |
|
1002 | + } |
|
1003 | + else |
|
1004 | + { |
|
837 | 1005 | $sql = "DELETE FROM $table WHERE expiry < $time"; |
838 | 1006 | $rs =& $conn->Execute($sql); |
839 | 1007 | ADODB_Session::_dumprs($rs); |
840 | - if ($rs) { |
|
1008 | + if ($rs) |
|
1009 | + { |
|
841 | 1010 | $rs->Close(); |
842 | 1011 | } |
843 | - if ($debug) { |
|
1012 | + if ($debug) |
|
1013 | + { |
|
844 | 1014 | ADOConnection::outp("<p><b>Garbage Collection</b>: $sql</p>"); |
845 | 1015 | } |
846 | 1016 | } |
847 | 1017 | |
848 | 1018 | // suggested by Cameron, "GaM3R" <[email protected]> |
849 | - if ($optimize) { |
|
1019 | + if ($optimize) |
|
1020 | + { |
|
850 | 1021 | $driver = ADODB_Session::driver(); |
851 | 1022 | |
852 | - if (preg_match('/mysql/i', $driver)) { |
|
1023 | + if (preg_match('/mysql/i', $driver)) |
|
1024 | + { |
|
853 | 1025 | $sql = "OPTIMIZE TABLE $table"; |
854 | 1026 | } |
855 | - if (preg_match('/postgres/i', $driver)) { |
|
1027 | + if (preg_match('/postgres/i', $driver)) |
|
1028 | + { |
|
856 | 1029 | $sql = "VACUUM $table"; |
857 | 1030 | } |
858 | - if (!empty($sql)) { |
|
1031 | + if (!empty($sql)) |
|
1032 | + { |
|
859 | 1033 | $conn->Execute($sql); |
860 | 1034 | } |
861 | 1035 | } |
862 | 1036 | |
863 | - if ($sync_seconds) { |
|
1037 | + if ($sync_seconds) |
|
1038 | + { |
|
864 | 1039 | $sql = 'SELECT '; |
865 | - if ($conn->dataProvider === 'oci8') { |
|
1040 | + if ($conn->dataProvider === 'oci8') |
|
1041 | + { |
|
866 | 1042 | $sql .= "TO_CHAR({$conn->sysTimeStamp}, 'RRRR-MM-DD HH24:MI:SS')"; |
867 | - } else { |
|
1043 | + } |
|
1044 | + else |
|
1045 | + { |
|
868 | 1046 | $sql .= $conn->sysTimeStamp; |
869 | 1047 | } |
870 | 1048 | $sql .= " FROM $table"; |
871 | 1049 | |
872 | 1050 | $rs =& $conn->SelectLimit($sql, 1); |
873 | - if ($rs && !$rs->EOF) { |
|
1051 | + if ($rs && !$rs->EOF) |
|
1052 | + { |
|
874 | 1053 | $dbts = reset($rs->fields); |
875 | 1054 | $rs->Close(); |
876 | 1055 | $dbt = $conn->UnixTimeStamp($dbts); |
877 | 1056 | $t = time(); |
878 | 1057 | |
879 | - if (abs($dbt - $t) >= $sync_seconds) { |
|
1058 | + if (abs($dbt - $t) >= $sync_seconds) |
|
1059 | + { |
|
880 | 1060 | $msg = __FILE__ . |
881 | 1061 | ": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: " . |
882 | 1062 | " database=$dbt ($dbts), webserver=$t (diff=". (abs($dbt - $t) / 60) . ' minutes)'; |
883 | 1063 | error_log($msg); |
884 | - if ($debug) { |
|
1064 | + if ($debug) |
|
1065 | + { |
|
885 | 1066 | ADOConnection::outp("<p>$msg</p>"); |
886 | 1067 | } |
887 | 1068 | } |
@@ -896,13 +1077,14 @@ discard block |
||
896 | 1077 | |
897 | 1078 | |
898 | 1079 | // for backwards compatability only |
899 | -function adodb_sess_open($save_path, $session_name, $persist = true) { |
|
1080 | +function adodb_sess_open($save_path, $session_name, $persist = true) |
|
1081 | +{ |
|
900 | 1082 | return ADODB_Session::open($save_path, $session_name, $persist); |
901 | 1083 | } |
902 | 1084 | |
903 | 1085 | // for backwards compatability only |
904 | 1086 | function adodb_sess_gc($t) |
905 | -{ |
|
1087 | +{ |
|
906 | 1088 | return ADODB_Session::gc($t); |
907 | 1089 | } |
908 | 1090 |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | $qkey = $conn->quote($key); |
580 | 580 | $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : ''; |
581 | 581 | |
582 | - $sql = "SELECT $data FROM $table WHERE $binary sesskey = $qkey AND expiry >= " . time(); |
|
582 | + $sql = "select $data FROM $table WHERE $binary sesskey = $qkey AND expiry >= " . time(); |
|
583 | 583 | /* Lock code does not work as it needs to hold transaction within whole page, and we don't know if |
584 | 584 | developer has commited elsewhere... :( |
585 | 585 | */ |
@@ -646,7 +646,7 @@ discard block |
||
646 | 646 | if ($debug) { |
647 | 647 | echo '<p>Session: Only updating date - crc32 not changed</p>'; |
648 | 648 | } |
649 | - $sql = "UPDATE $table SET expiry = ".$conn->Param('0')." WHERE $binary sesskey = ".$conn->Param('1')." AND expiry >= ".$conn->Param('2'); |
|
649 | + $sql = "update $table SET expiry = ".$conn->Param('0')." WHERE $binary sesskey = ".$conn->Param('1')." AND expiry >= ".$conn->Param('2'); |
|
650 | 650 | $rs =& $conn->Execute($sql,array($expiry,$key,time())); |
651 | 651 | ADODB_Session::_dumprs($rs); |
652 | 652 | if ($rs) { |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | $rs =& $conn->Execute("SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = $qkey"); |
696 | 696 | ADODB_Session::_dumprs($rs); |
697 | 697 | if ($rs && reset($rs->fields) > 0) { |
698 | - $sql = "UPDATE $table SET expiry = $expiry, $data = $lob_value WHERE sesskey = $qkey"; |
|
698 | + $sql = "update $table SET expiry = $expiry, $data = $lob_value WHERE sesskey = $qkey"; |
|
699 | 699 | } else { |
700 | 700 | $sql = "INSERT INTO $table (expiry, $data, sesskey) VALUES ($expiry, $lob_value, $qkey)"; |
701 | 701 | } |
@@ -853,7 +853,7 @@ discard block |
||
853 | 853 | $sql = "OPTIMIZE TABLE $table"; |
854 | 854 | } |
855 | 855 | if (preg_match('/postgres/i', $driver)) { |
856 | - $sql = "VACUUM $table"; |
|
856 | + $sql = "vacuum $table"; |
|
857 | 857 | } |
858 | 858 | if (!empty($sql)) { |
859 | 859 | $conn->Execute($sql); |
@@ -1,6 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | // Session Encryption by Ari Kuorikoski <[email protected]> |
3 | 3 | class MD5Crypt{ |
4 | + |
|
5 | + /** |
|
6 | + * @param string $txt |
|
7 | + */ |
|
4 | 8 | function keyED($txt,$encrypt_key) |
5 | 9 | { |
6 | 10 | $encrypt_key = md5($encrypt_key); |
@@ -1,43 +1,43 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Session Encryption by Ari Kuorikoski <[email protected]> |
3 | -class MD5Crypt{ |
|
4 | - function keyED($txt,$encrypt_key) |
|
3 | +class MD5Crypt { |
|
4 | + function keyED($txt, $encrypt_key) |
|
5 | 5 | { |
6 | 6 | $encrypt_key = md5($encrypt_key); |
7 | - $ctr=0; |
|
7 | + $ctr = 0; |
|
8 | 8 | $tmp = ""; |
9 | - for ($i=0;$i<strlen($txt);$i++){ |
|
10 | - if ($ctr==strlen($encrypt_key)) $ctr=0; |
|
11 | - $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1); |
|
9 | + for ($i = 0; $i < strlen($txt); $i++) { |
|
10 | + if ($ctr == strlen($encrypt_key)) $ctr = 0; |
|
11 | + $tmp .= substr($txt, $i, 1)^substr($encrypt_key, $ctr, 1); |
|
12 | 12 | $ctr++; |
13 | 13 | } |
14 | 14 | return $tmp; |
15 | 15 | } |
16 | 16 | |
17 | - function Encrypt($txt,$key) |
|
17 | + function Encrypt($txt, $key) |
|
18 | 18 | { |
19 | - srand((double)microtime()*1000000); |
|
20 | - $encrypt_key = md5(rand(0,32000)); |
|
21 | - $ctr=0; |
|
19 | + srand((double)microtime() * 1000000); |
|
20 | + $encrypt_key = md5(rand(0, 32000)); |
|
21 | + $ctr = 0; |
|
22 | 22 | $tmp = ""; |
23 | - for ($i=0;$i<strlen($txt);$i++) |
|
23 | + for ($i = 0; $i < strlen($txt); $i++) |
|
24 | 24 | { |
25 | - if ($ctr==strlen($encrypt_key)) $ctr=0; |
|
26 | - $tmp.= substr($encrypt_key,$ctr,1) . |
|
27 | - (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1)); |
|
25 | + if ($ctr == strlen($encrypt_key)) $ctr = 0; |
|
26 | + $tmp .= substr($encrypt_key, $ctr, 1). |
|
27 | + (substr($txt, $i, 1)^substr($encrypt_key, $ctr, 1)); |
|
28 | 28 | $ctr++; |
29 | 29 | } |
30 | - return base64_encode($this->keyED($tmp,$key)); |
|
30 | + return base64_encode($this->keyED($tmp, $key)); |
|
31 | 31 | } |
32 | 32 | |
33 | - function Decrypt($txt,$key) |
|
33 | + function Decrypt($txt, $key) |
|
34 | 34 | { |
35 | - $txt = $this->keyED(base64_decode($txt),$key); |
|
35 | + $txt = $this->keyED(base64_decode($txt), $key); |
|
36 | 36 | $tmp = ""; |
37 | - for ($i=0;$i<strlen($txt);$i++){ |
|
38 | - $md5 = substr($txt,$i,1); |
|
37 | + for ($i = 0; $i < strlen($txt); $i++) { |
|
38 | + $md5 = substr($txt, $i, 1); |
|
39 | 39 | $i++; |
40 | - $tmp.= (substr($txt,$i,1) ^ $md5); |
|
40 | + $tmp .= (substr($txt, $i, 1)^$md5); |
|
41 | 41 | } |
42 | 42 | return $tmp; |
43 | 43 | } |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | function RandPass() |
46 | 46 | { |
47 | 47 | $randomPassword = ""; |
48 | - srand((double)microtime()*1000000); |
|
49 | - for($i=0;$i<8;$i++) |
|
48 | + srand((double)microtime() * 1000000); |
|
49 | + for ($i = 0; $i < 8; $i++) |
|
50 | 50 | { |
51 | - $randnumber = rand(48,120); |
|
51 | + $randnumber = rand(48, 120); |
|
52 | 52 | |
53 | 53 | while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96)) |
54 | 54 | { |
55 | - $randnumber = rand(48,120); |
|
55 | + $randnumber = rand(48, 120); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | $randomPassword .= chr($randnumber); |
@@ -1,13 +1,18 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Session Encryption by Ari Kuorikoski <[email protected]> |
3 | -class MD5Crypt{ |
|
3 | +class MD5Crypt |
|
4 | +{ |
|
4 | 5 | function keyED($txt,$encrypt_key) |
5 | 6 | { |
6 | 7 | $encrypt_key = md5($encrypt_key); |
7 | 8 | $ctr=0; |
8 | 9 | $tmp = ""; |
9 | - for ($i=0;$i<strlen($txt);$i++){ |
|
10 | - if ($ctr==strlen($encrypt_key)) $ctr=0; |
|
10 | + for ($i=0;$i<strlen($txt);$i++) |
|
11 | + { |
|
12 | + if ($ctr==strlen($encrypt_key)) |
|
13 | + { |
|
14 | + $ctr=0; |
|
15 | + } |
|
11 | 16 | $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1); |
12 | 17 | $ctr++; |
13 | 18 | } |
@@ -22,7 +27,10 @@ discard block |
||
22 | 27 | $tmp = ""; |
23 | 28 | for ($i=0;$i<strlen($txt);$i++) |
24 | 29 | { |
25 | - if ($ctr==strlen($encrypt_key)) $ctr=0; |
|
30 | + if ($ctr==strlen($encrypt_key)) |
|
31 | + { |
|
32 | + $ctr=0; |
|
33 | + } |
|
26 | 34 | $tmp.= substr($encrypt_key,$ctr,1) . |
27 | 35 | (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1)); |
28 | 36 | $ctr++; |
@@ -34,7 +42,8 @@ discard block |
||
34 | 42 | { |
35 | 43 | $txt = $this->keyED(base64_decode($txt),$key); |
36 | 44 | $tmp = ""; |
37 | - for ($i=0;$i<strlen($txt);$i++){ |
|
45 | + for ($i=0;$i<strlen($txt);$i++) |
|
46 | + { |
|
38 | 47 | $md5 = substr($txt,$i,1); |
39 | 48 | $i++; |
40 | 49 | $tmp.= (substr($txt,$i,1) ^ $md5); |
@@ -60,6 +60,10 @@ |
||
60 | 60 | if ($fp) fclose($fp); |
61 | 61 | } |
62 | 62 | |
63 | +/** |
|
64 | + * @param string $sep |
|
65 | + * @param string $sepreplace |
|
66 | + */ |
|
63 | 67 | function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote = '"',$escquote = '"',$replaceNewLine = ' ') |
64 | 68 | { |
65 | 69 | if (!$rs) return ''; |
@@ -22,45 +22,45 @@ discard block |
||
22 | 22 | */ |
23 | 23 | |
24 | 24 | // returns a recordset as a csv string |
25 | -function rs2csv(&$rs,$addtitles=true) |
|
25 | +function rs2csv(&$rs, $addtitles = true) |
|
26 | 26 | { |
27 | - return _adodb_export($rs,',',',',false,$addtitles); |
|
27 | + return _adodb_export($rs, ',', ',', false, $addtitles); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | // writes recordset to csv file |
31 | -function rs2csvfile(&$rs,$fp,$addtitles=true) |
|
31 | +function rs2csvfile(&$rs, $fp, $addtitles = true) |
|
32 | 32 | { |
33 | - _adodb_export($rs,',',',',$fp,$addtitles); |
|
33 | + _adodb_export($rs, ',', ',', $fp, $addtitles); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | // write recordset as csv string to stdout |
37 | -function rs2csvout(&$rs,$addtitles=true) |
|
37 | +function rs2csvout(&$rs, $addtitles = true) |
|
38 | 38 | { |
39 | - $fp = fopen('php://stdout','wb'); |
|
40 | - _adodb_export($rs,',',',',true,$addtitles); |
|
39 | + $fp = fopen('php://stdout', 'wb'); |
|
40 | + _adodb_export($rs, ',', ',', true, $addtitles); |
|
41 | 41 | fclose($fp); |
42 | 42 | } |
43 | 43 | |
44 | -function rs2tab(&$rs,$addtitles=true) |
|
44 | +function rs2tab(&$rs, $addtitles = true) |
|
45 | 45 | { |
46 | - return _adodb_export($rs,"\t",',',false,$addtitles); |
|
46 | + return _adodb_export($rs, "\t", ',', false, $addtitles); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | // to file pointer |
50 | -function rs2tabfile(&$rs,$fp,$addtitles=true) |
|
50 | +function rs2tabfile(&$rs, $fp, $addtitles = true) |
|
51 | 51 | { |
52 | - _adodb_export($rs,"\t",',',$fp,$addtitles); |
|
52 | + _adodb_export($rs, "\t", ',', $fp, $addtitles); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | // to stdout |
56 | -function rs2tabout(&$rs,$addtitles=true) |
|
56 | +function rs2tabout(&$rs, $addtitles = true) |
|
57 | 57 | { |
58 | - $fp = fopen('php://stdout','wb'); |
|
59 | - _adodb_export($rs,"\t",' ',true,$addtitles); |
|
58 | + $fp = fopen('php://stdout', 'wb'); |
|
59 | + _adodb_export($rs, "\t", ' ', true, $addtitles); |
|
60 | 60 | if ($fp) fclose($fp); |
61 | 61 | } |
62 | 62 | |
63 | -function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote = '"',$escquote = '"',$replaceNewLine = ' ') |
|
63 | +function _adodb_export(&$rs, $sep, $sepreplace, $fp = false, $addtitles = true, $quote = '"', $escquote = '"', $replaceNewLine = ' ') |
|
64 | 64 | { |
65 | 65 | if (!$rs) return ''; |
66 | 66 | //---------- |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | if ($addtitles) { |
74 | 74 | $fieldTypes = $rs->FieldTypesArray(); |
75 | 75 | reset($fieldTypes); |
76 | - while(list(,$o) = each($fieldTypes)) { |
|
76 | + while (list(,$o) = each($fieldTypes)) { |
|
77 | 77 | |
78 | 78 | $v = $o->name; |
79 | - if ($escquote) $v = str_replace($quote,$escquotequote,$v); |
|
80 | - $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); |
|
79 | + if ($escquote) $v = str_replace($quote, $escquotequote, $v); |
|
80 | + $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n", $replaceNewLine, str_replace($sep, $sepreplace, $v)))); |
|
81 | 81 | $elements[] = $v; |
82 | 82 | |
83 | 83 | } |
@@ -93,22 +93,22 @@ discard block |
||
93 | 93 | $i = 0; |
94 | 94 | |
95 | 95 | if ($hasNumIndex) { |
96 | - for ($j=0; $j < $max; $j++) { |
|
96 | + for ($j = 0; $j < $max; $j++) { |
|
97 | 97 | $v = $rs->fields[$j]; |
98 | 98 | if (!is_object($v)) $v = trim($v); |
99 | 99 | else $v = 'Object'; |
100 | - if ($escquote) $v = str_replace($quote,$escquotequote,$v); |
|
101 | - $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); |
|
100 | + if ($escquote) $v = str_replace($quote, $escquotequote, $v); |
|
101 | + $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n", $replaceNewLine, str_replace($sep, $sepreplace, $v)))); |
|
102 | 102 | |
103 | - if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; |
|
103 | + if (strpos($v, $sep) !== false || strpos($v, $quote) !== false) $elements[] = "$quote$v$quote"; |
|
104 | 104 | else $elements[] = $v; |
105 | 105 | } |
106 | 106 | } else { // ASSOCIATIVE ARRAY |
107 | - foreach($rs->fields as $v) { |
|
108 | - if ($escquote) $v = str_replace($quote,$escquotequote,trim($v)); |
|
109 | - $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); |
|
107 | + foreach ($rs->fields as $v) { |
|
108 | + if ($escquote) $v = str_replace($quote, $escquotequote, trim($v)); |
|
109 | + $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n", $replaceNewLine, str_replace($sep, $sepreplace, $v)))); |
|
110 | 110 | |
111 | - if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; |
|
111 | + if (strpos($v, $sep) !== false || strpos($v, $quote) !== false) $elements[] = "$quote$v$quote"; |
|
112 | 112 | else $elements[] = $v; |
113 | 113 | } |
114 | 114 | } |
@@ -117,14 +117,14 @@ discard block |
||
117 | 117 | $line += 1; |
118 | 118 | if ($fp && ($line % $BUFLINES) == 0) { |
119 | 119 | if ($fp === true) echo $s; |
120 | - else fwrite($fp,$s); |
|
120 | + else fwrite($fp, $s); |
|
121 | 121 | $s = ''; |
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | 125 | if ($fp) { |
126 | 126 | if ($fp === true) echo $s; |
127 | - else fwrite($fp,$s); |
|
127 | + else fwrite($fp, $s); |
|
128 | 128 | $s = ''; |
129 | 129 | } |
130 | 130 |
@@ -57,12 +57,18 @@ discard block |
||
57 | 57 | { |
58 | 58 | $fp = fopen('php://stdout','wb'); |
59 | 59 | _adodb_export($rs,"\t",' ',true,$addtitles); |
60 | - if ($fp) fclose($fp); |
|
61 | -} |
|
60 | + if ($fp) |
|
61 | + { |
|
62 | + fclose($fp); |
|
63 | + } |
|
64 | + } |
|
62 | 65 | |
63 | 66 | function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote = '"',$escquote = '"',$replaceNewLine = ' ') |
64 | 67 | { |
65 | - if (!$rs) return ''; |
|
68 | + if (!$rs) |
|
69 | + { |
|
70 | + return ''; |
|
71 | + } |
|
66 | 72 | //---------- |
67 | 73 | // CONSTANTS |
68 | 74 | $NEWLINE = "\r\n"; |
@@ -70,13 +76,18 @@ discard block |
||
70 | 76 | $escquotequote = $escquote.$quote; |
71 | 77 | $s = ''; |
72 | 78 | |
73 | - if ($addtitles) { |
|
79 | + if ($addtitles) |
|
80 | + { |
|
74 | 81 | $fieldTypes = $rs->FieldTypesArray(); |
75 | 82 | reset($fieldTypes); |
76 | - while(list(,$o) = each($fieldTypes)) { |
|
83 | + while(list(,$o) = each($fieldTypes)) |
|
84 | + { |
|
77 | 85 | |
78 | 86 | $v = $o->name; |
79 | - if ($escquote) $v = str_replace($quote,$escquotequote,$v); |
|
87 | + if ($escquote) |
|
88 | + { |
|
89 | + $v = str_replace($quote,$escquotequote,$v); |
|
90 | + } |
|
80 | 91 | $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); |
81 | 92 | $elements[] = $v; |
82 | 93 | |
@@ -88,43 +99,83 @@ discard block |
||
88 | 99 | $line = 0; |
89 | 100 | $max = $rs->FieldCount(); |
90 | 101 | |
91 | - while (!$rs->EOF) { |
|
102 | + while (!$rs->EOF) |
|
103 | + { |
|
92 | 104 | $elements = array(); |
93 | 105 | $i = 0; |
94 | 106 | |
95 | - if ($hasNumIndex) { |
|
96 | - for ($j=0; $j < $max; $j++) { |
|
107 | + if ($hasNumIndex) |
|
108 | + { |
|
109 | + for ($j=0; $j < $max; $j++) |
|
110 | + { |
|
97 | 111 | $v = $rs->fields[$j]; |
98 | - if (!is_object($v)) $v = trim($v); |
|
99 | - else $v = 'Object'; |
|
100 | - if ($escquote) $v = str_replace($quote,$escquotequote,$v); |
|
112 | + if (!is_object($v)) |
|
113 | + { |
|
114 | + $v = trim($v); |
|
115 | + } |
|
116 | + else { |
|
117 | + $v = 'Object'; |
|
118 | + } |
|
119 | + if ($escquote) |
|
120 | + { |
|
121 | + $v = str_replace($quote,$escquotequote,$v); |
|
122 | + } |
|
101 | 123 | $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); |
102 | 124 | |
103 | - if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; |
|
104 | - else $elements[] = $v; |
|
125 | + if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) |
|
126 | + { |
|
127 | + $elements[] = "$quote$v$quote"; |
|
128 | + } |
|
129 | + else { |
|
130 | + $elements[] = $v; |
|
131 | + } |
|
105 | 132 | } |
106 | - } else { // ASSOCIATIVE ARRAY |
|
107 | - foreach($rs->fields as $v) { |
|
108 | - if ($escquote) $v = str_replace($quote,$escquotequote,trim($v)); |
|
133 | + } |
|
134 | + else |
|
135 | + { |
|
136 | +// ASSOCIATIVE ARRAY |
|
137 | + foreach($rs->fields as $v) |
|
138 | + { |
|
139 | + if ($escquote) |
|
140 | + { |
|
141 | + $v = str_replace($quote,$escquotequote,trim($v)); |
|
142 | + } |
|
109 | 143 | $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); |
110 | 144 | |
111 | - if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; |
|
112 | - else $elements[] = $v; |
|
145 | + if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) |
|
146 | + { |
|
147 | + $elements[] = "$quote$v$quote"; |
|
148 | + } |
|
149 | + else { |
|
150 | + $elements[] = $v; |
|
151 | + } |
|
113 | 152 | } |
114 | 153 | } |
115 | 154 | $s .= implode($sep, $elements).$NEWLINE; |
116 | 155 | $rs->MoveNext(); |
117 | 156 | $line += 1; |
118 | - if ($fp && ($line % $BUFLINES) == 0) { |
|
119 | - if ($fp === true) echo $s; |
|
120 | - else fwrite($fp,$s); |
|
157 | + if ($fp && ($line % $BUFLINES) == 0) |
|
158 | + { |
|
159 | + if ($fp === true) |
|
160 | + { |
|
161 | + echo $s; |
|
162 | + } |
|
163 | + else { |
|
164 | + fwrite($fp,$s); |
|
165 | + } |
|
121 | 166 | $s = ''; |
122 | 167 | } |
123 | 168 | } |
124 | 169 | |
125 | - if ($fp) { |
|
126 | - if ($fp === true) echo $s; |
|
127 | - else fwrite($fp,$s); |
|
170 | + if ($fp) |
|
171 | + { |
|
172 | + if ($fp === true) |
|
173 | + { |
|
174 | + echo $s; |
|
175 | + } |
|
176 | + else { |
|
177 | + fwrite($fp,$s); |
|
178 | + } |
|
128 | 179 | $s = ''; |
129 | 180 | } |
130 | 181 |