@@ -6,6 +6,9 @@ discard block |
||
6 | 6 | public $dbs = array(); |
7 | 7 | public $latest_schema = 37; |
8 | 8 | |
9 | + /** |
|
10 | + * @param string $dbname |
|
11 | + */ |
|
9 | 12 | public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) { |
10 | 13 | global $globalDBdriver, $globalNoDB; |
11 | 14 | if (isset($globalNoDB) && $globalNoDB === TRUE) { |
@@ -140,6 +143,9 @@ discard block |
||
140 | 143 | return true; |
141 | 144 | } |
142 | 145 | |
146 | + /** |
|
147 | + * @param string $table |
|
148 | + */ |
|
143 | 149 | public function tableExists($table) |
144 | 150 | { |
145 | 151 | global $globalDBdriver, $globalDBname; |
@@ -189,6 +195,11 @@ discard block |
||
189 | 195 | /* |
190 | 196 | * Check if index exist |
191 | 197 | */ |
198 | + |
|
199 | + /** |
|
200 | + * @param string $table |
|
201 | + * @param string $index |
|
202 | + */ |
|
192 | 203 | public function indexExists($table,$index) |
193 | 204 | { |
194 | 205 | global $globalDBdriver, $globalDBname; |
@@ -231,6 +242,10 @@ discard block |
||
231 | 242 | return $columns; |
232 | 243 | } |
233 | 244 | |
245 | + /** |
|
246 | + * @param string $table |
|
247 | + * @param string $column |
|
248 | + */ |
|
234 | 249 | public function getColumnType($table,$column) { |
235 | 250 | $select = $this->db->query('SELECT '.$column.' FROM '.$table); |
236 | 251 | $tomet = $select->getColumnMeta(0); |
@@ -241,6 +256,11 @@ discard block |
||
241 | 256 | * Check if a column name exist in a table |
242 | 257 | * @return Boolean column exist or not |
243 | 258 | */ |
259 | + |
|
260 | + /** |
|
261 | + * @param string $table |
|
262 | + * @param string $name |
|
263 | + */ |
|
244 | 264 | public function checkColumnName($table,$name) |
245 | 265 | { |
246 | 266 | global $globalDBdriver, $globalDBname; |
@@ -7,35 +7,35 @@ discard block |
||
7 | 7 | public $latest_schema = 37; |
8 | 8 | |
9 | 9 | public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) { |
10 | - global $globalDBdriver, $globalNoDB; |
|
11 | - if (isset($globalNoDB) && $globalNoDB === TRUE) { |
|
10 | + global $globalDBdriver, $globalNoDB; |
|
11 | + if (isset($globalNoDB) && $globalNoDB === TRUE) { |
|
12 | 12 | $this->db = null; |
13 | - } else { |
|
13 | + } else { |
|
14 | 14 | if ($dbc === null) { |
15 | - if ($this->db === null && $dbname === null) { |
|
15 | + if ($this->db === null && $dbname === null) { |
|
16 | 16 | if ($user === null && $pass === null) { |
17 | - $this->createDBConnection(); |
|
17 | + $this->createDBConnection(); |
|
18 | 18 | } else { |
19 | - $this->createDBConnection(null,$user,$pass); |
|
19 | + $this->createDBConnection(null,$user,$pass); |
|
20 | 20 | } |
21 | - } else { |
|
21 | + } else { |
|
22 | 22 | $this->createDBConnection($dbname); |
23 | - } |
|
23 | + } |
|
24 | 24 | } elseif ($dbname === null || $dbname === 'default') { |
25 | - $this->db = $dbc; |
|
26 | - if ($this->connectionExists() === false) { |
|
25 | + $this->db = $dbc; |
|
26 | + if ($this->connectionExists() === false) { |
|
27 | 27 | /* |
28 | 28 | echo 'Restart Connection !!!'."\n"; |
29 | 29 | $e = new \Exception; |
30 | 30 | var_dump($e->getTraceAsString()); |
31 | 31 | */ |
32 | 32 | $this->createDBConnection(); |
33 | - } |
|
33 | + } |
|
34 | 34 | } else { |
35 | - //$this->connectionExists(); |
|
36 | - $this->dbs[$dbname] = $dbc; |
|
35 | + //$this->connectionExists(); |
|
36 | + $this->dbs[$dbname] = $dbc; |
|
37 | + } |
|
37 | 38 | } |
38 | - } |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | public function db() { |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | - * Creates the database connection |
|
59 | - * |
|
60 | - * @return Boolean of the database connection |
|
61 | - * |
|
62 | - */ |
|
58 | + * Creates the database connection |
|
59 | + * |
|
60 | + * @return Boolean of the database connection |
|
61 | + * |
|
62 | + */ |
|
63 | 63 | |
64 | 64 | public function createDBConnection($DBname = null, $user = null, $pass = null) |
65 | 65 | { |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | return false; |
157 | 157 | } |
158 | 158 | if($results->rowCount()>0) { |
159 | - return true; |
|
159 | + return true; |
|
160 | 160 | } |
161 | 161 | else return false; |
162 | 162 | } |
@@ -173,14 +173,14 @@ discard block |
||
173 | 173 | $sum = $sum->fetchColumn(0); |
174 | 174 | } else $sum = 0; |
175 | 175 | if (intval($sum) !== 2) { |
176 | - return false; |
|
176 | + return false; |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | } catch(PDOException $e) { |
180 | 180 | if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) { |
181 | - throw $e; |
|
182 | - } |
|
183 | - //echo 'error ! '.$e->getMessage(); |
|
181 | + throw $e; |
|
182 | + } |
|
183 | + //echo 'error ! '.$e->getMessage(); |
|
184 | 184 | return false; |
185 | 185 | } |
186 | 186 | return true; |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | $version = 0; |
285 | 285 | if ($this->tableExists('aircraft')) { |
286 | 286 | if (!$this->tableExists('config')) { |
287 | - $version = '1'; |
|
288 | - return $version; |
|
287 | + $version = '1'; |
|
288 | + return $version; |
|
289 | 289 | } else { |
290 | 290 | $query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1"; |
291 | 291 | try { |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | * @return Boolean if latest version or not |
307 | 307 | */ |
308 | 308 | public function latest() { |
309 | - global $globalNoDB; |
|
310 | - if (isset($globalNoDB) && $globalNoDB === TRUE) return true; |
|
311 | - if ($this->check_schema_version() == $this->latest_schema) return true; |
|
312 | - else return false; |
|
309 | + global $globalNoDB; |
|
310 | + if (isset($globalNoDB) && $globalNoDB === TRUE) return true; |
|
311 | + if ($this->check_schema_version() == $this->latest_schema) return true; |
|
312 | + else return false; |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | } |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | require_once(dirname(__FILE__).'/settings.php'); |
3 | 3 | |
4 | -class Connection{ |
|
4 | +class Connection { |
|
5 | 5 | public $db = null; |
6 | 6 | public $dbs = array(); |
7 | 7 | public $latest_schema = 37; |
8 | 8 | |
9 | - public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) { |
|
9 | + public function __construct($dbc = null, $dbname = null, $user = null, $pass = null) { |
|
10 | 10 | global $globalDBdriver, $globalNoDB; |
11 | 11 | if (isset($globalNoDB) && $globalNoDB === TRUE) { |
12 | 12 | $this->db = null; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | if ($user === null && $pass === null) { |
17 | 17 | $this->createDBConnection(); |
18 | 18 | } else { |
19 | - $this->createDBConnection(null,$user,$pass); |
|
19 | + $this->createDBConnection(null, $user, $pass); |
|
20 | 20 | } |
21 | 21 | } else { |
22 | 22 | $this->createDBConnection($dbname); |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | while (true) { |
100 | 100 | try { |
101 | 101 | if ($globalDBSdriver == 'mysql') { |
102 | - $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser, $globalDBSpass); |
|
102 | + $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser, $globalDBSpass); |
|
103 | 103 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
104 | 104 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
105 | - $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
|
106 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500); |
|
107 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
108 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
109 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
105 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); |
|
106 | + if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 500); |
|
107 | + else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut); |
|
108 | + if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true); |
|
109 | + else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent); |
|
110 | 110 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
111 | 111 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); |
112 | 112 | // Workaround against "ONLY_FULL_GROUP_BY" mode |
@@ -116,19 +116,19 @@ discard block |
||
116 | 116 | $this->dbs[$DBname]->exec('SET SESSION time_zone = "+00:00"'); |
117 | 117 | //$this->dbs[$DBname]->exec('SET @@session.time_zone = "+00:00"'); |
118 | 118 | } else { |
119 | - $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser, $globalDBSpass); |
|
119 | + $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser, $globalDBSpass); |
|
120 | 120 | //$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
121 | 121 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
122 | - $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
|
123 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
124 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
125 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
126 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
122 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); |
|
123 | + if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 200); |
|
124 | + else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut); |
|
125 | + if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true); |
|
126 | + else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent); |
|
127 | 127 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
128 | 128 | $this->dbs[$DBname]->exec('SET timezone="UTC"'); |
129 | 129 | } |
130 | 130 | break; |
131 | - } catch(PDOException $e) { |
|
131 | + } catch (PDOException $e) { |
|
132 | 132 | $i++; |
133 | 133 | if (isset($globalDebug) && $globalDebug) echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n"; |
134 | 134 | //exit; |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | try { |
153 | 153 | //$Connection = new Connection(); |
154 | 154 | $results = $this->db->query($query); |
155 | - } catch(PDOException $e) { |
|
155 | + } catch (PDOException $e) { |
|
156 | 156 | return false; |
157 | 157 | } |
158 | - if($results->rowCount()>0) { |
|
158 | + if ($results->rowCount() > 0) { |
|
159 | 159 | return true; |
160 | 160 | } |
161 | 161 | else return false; |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | return false; |
177 | 177 | } |
178 | 178 | |
179 | - } catch(PDOException $e) { |
|
180 | - if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) { |
|
179 | + } catch (PDOException $e) { |
|
180 | + if ($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) { |
|
181 | 181 | throw $e; |
182 | 182 | } |
183 | 183 | //echo 'error ! '.$e->getMessage(); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | /* |
190 | 190 | * Check if index exist |
191 | 191 | */ |
192 | - public function indexExists($table,$index) |
|
192 | + public function indexExists($table, $index) |
|
193 | 193 | { |
194 | 194 | global $globalDBdriver, $globalDBname; |
195 | 195 | if ($globalDBdriver == 'mysql') { |
@@ -200,11 +200,11 @@ discard block |
||
200 | 200 | try { |
201 | 201 | //$Connection = new Connection(); |
202 | 202 | $results = $this->db->query($query); |
203 | - } catch(PDOException $e) { |
|
203 | + } catch (PDOException $e) { |
|
204 | 204 | return false; |
205 | 205 | } |
206 | 206 | $nb = $results->fetchAll(PDO::FETCH_ASSOC); |
207 | - if($nb[0]['nb'] > 0) { |
|
207 | + if ($nb[0]['nb'] > 0) { |
|
208 | 208 | return true; |
209 | 209 | } |
210 | 210 | else return false; |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | $query = "SELECT * FROM ".$table." LIMIT 0"; |
220 | 220 | try { |
221 | 221 | $results = $this->db->query($query); |
222 | - } catch(PDOException $e) { |
|
222 | + } catch (PDOException $e) { |
|
223 | 223 | return "error : ".$e->getMessage()."\n"; |
224 | 224 | } |
225 | 225 | $columns = array(); |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | return $columns; |
232 | 232 | } |
233 | 233 | |
234 | - public function getColumnType($table,$column) { |
|
234 | + public function getColumnType($table, $column) { |
|
235 | 235 | $select = $this->db->query('SELECT '.$column.' FROM '.$table); |
236 | 236 | $tomet = $select->getColumnMeta(0); |
237 | 237 | return $tomet['native_type']; |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * Check if a column name exist in a table |
242 | 242 | * @return Boolean column exist or not |
243 | 243 | */ |
244 | - public function checkColumnName($table,$name) |
|
244 | + public function checkColumnName($table, $name) |
|
245 | 245 | { |
246 | 246 | global $globalDBdriver, $globalDBname; |
247 | 247 | if ($globalDBdriver == 'mysql') { |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | } |
252 | 252 | try { |
253 | 253 | $sth = $this->db()->prepare($query); |
254 | - $sth->execute(array(':database' => $globalDBname,':table' => $table,':name' => $name)); |
|
255 | - } catch(PDOException $e) { |
|
254 | + $sth->execute(array(':database' => $globalDBname, ':table' => $table, ':name' => $name)); |
|
255 | + } catch (PDOException $e) { |
|
256 | 256 | echo "error : ".$e->getMessage()."\n"; |
257 | 257 | } |
258 | 258 | $result = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | try { |
292 | 292 | $sth = $this->db->prepare($query); |
293 | 293 | $sth->execute(); |
294 | - } catch(PDOException $e) { |
|
294 | + } catch (PDOException $e) { |
|
295 | 295 | return "error : ".$e->getMessage()."\n"; |
296 | 296 | } |
297 | 297 | $result = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -72,8 +72,11 @@ discard block |
||
72 | 72 | $globalDBSname = $globalDBname; |
73 | 73 | $globalDBSuser = $globalDBuser; |
74 | 74 | $globalDBSpass = $globalDBpass; |
75 | - if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') $globalDBSport = 3306; |
|
76 | - else $globalDBSport = $globalDBport; |
|
75 | + if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') { |
|
76 | + $globalDBSport = 3306; |
|
77 | + } else { |
|
78 | + $globalDBSport = $globalDBport; |
|
79 | + } |
|
77 | 80 | } else { |
78 | 81 | $DBname = 'default'; |
79 | 82 | $globalDBSdriver = $globalDBdriver; |
@@ -81,8 +84,11 @@ discard block |
||
81 | 84 | $globalDBSname = $globalDBname; |
82 | 85 | $globalDBSuser = $user; |
83 | 86 | $globalDBSpass = $pass; |
84 | - if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') $globalDBSport = 3306; |
|
85 | - else $globalDBSport = $globalDBport; |
|
87 | + if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') { |
|
88 | + $globalDBSport = 3306; |
|
89 | + } else { |
|
90 | + $globalDBSport = $globalDBport; |
|
91 | + } |
|
86 | 92 | } |
87 | 93 | } else { |
88 | 94 | $globalDBSdriver = $globalDB[$DBname]['driver']; |
@@ -90,11 +96,16 @@ discard block |
||
90 | 96 | $globalDBSname = $globalDB[$DBname]['name']; |
91 | 97 | $globalDBSuser = $globalDB[$DBname]['user']; |
92 | 98 | $globalDBSpass = $globalDB[$DBname]['pass']; |
93 | - if (isset($globalDB[$DBname]['port'])) $globalDBSport = $globalDB[$DBname]['port']; |
|
94 | - else $globalDBSport = 3306; |
|
99 | + if (isset($globalDB[$DBname]['port'])) { |
|
100 | + $globalDBSport = $globalDB[$DBname]['port']; |
|
101 | + } else { |
|
102 | + $globalDBSport = 3306; |
|
103 | + } |
|
95 | 104 | } |
96 | 105 | // Set number of try to connect to DB |
97 | - if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) $globalDBretry = 5; |
|
106 | + if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) { |
|
107 | + $globalDBretry = 5; |
|
108 | + } |
|
98 | 109 | $i = 0; |
99 | 110 | while (true) { |
100 | 111 | try { |
@@ -103,10 +114,16 @@ discard block |
||
103 | 114 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
104 | 115 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
105 | 116 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
106 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500); |
|
107 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
108 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
109 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
117 | + if (!isset($globalDBTimeOut)) { |
|
118 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500); |
|
119 | + } else { |
|
120 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
121 | + } |
|
122 | + if (!isset($globalDBPersistent)) { |
|
123 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
124 | + } else { |
|
125 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
126 | + } |
|
110 | 127 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
111 | 128 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); |
112 | 129 | // Workaround against "ONLY_FULL_GROUP_BY" mode |
@@ -120,23 +137,35 @@ discard block |
||
120 | 137 | //$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
121 | 138 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
122 | 139 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
123 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
124 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
125 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
126 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
140 | + if (!isset($globalDBTimeOut)) { |
|
141 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
142 | + } else { |
|
143 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
144 | + } |
|
145 | + if (!isset($globalDBPersistent)) { |
|
146 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
147 | + } else { |
|
148 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
149 | + } |
|
127 | 150 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
128 | 151 | $this->dbs[$DBname]->exec('SET timezone="UTC"'); |
129 | 152 | } |
130 | 153 | break; |
131 | 154 | } catch(PDOException $e) { |
132 | 155 | $i++; |
133 | - if (isset($globalDebug) && $globalDebug) echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n"; |
|
156 | + if (isset($globalDebug) && $globalDebug) { |
|
157 | + echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n"; |
|
158 | + } |
|
134 | 159 | //exit; |
135 | - if ($i > $globalDBretry) return false; |
|
160 | + if ($i > $globalDBretry) { |
|
161 | + return false; |
|
162 | + } |
|
136 | 163 | //return false; |
137 | 164 | } |
138 | 165 | } |
139 | - if ($DBname === 'default') $this->db = $this->dbs['default']; |
|
166 | + if ($DBname === 'default') { |
|
167 | + $this->db = $this->dbs['default']; |
|
168 | + } |
|
140 | 169 | return true; |
141 | 170 | } |
142 | 171 | |
@@ -148,7 +177,9 @@ discard block |
||
148 | 177 | } else { |
149 | 178 | $query = "SELECT * FROM pg_catalog.pg_tables WHERE tablename = '".$table."'"; |
150 | 179 | } |
151 | - if ($this->db == NULL) return false; |
|
180 | + if ($this->db == NULL) { |
|
181 | + return false; |
|
182 | + } |
|
152 | 183 | try { |
153 | 184 | //$Connection = new Connection(); |
154 | 185 | $results = $this->db->query($query); |
@@ -157,21 +188,28 @@ discard block |
||
157 | 188 | } |
158 | 189 | if($results->rowCount()>0) { |
159 | 190 | return true; |
191 | + } else { |
|
192 | + return false; |
|
160 | 193 | } |
161 | - else return false; |
|
162 | 194 | } |
163 | 195 | |
164 | 196 | public function connectionExists() |
165 | 197 | { |
166 | 198 | global $globalDBdriver, $globalDBCheckConnection; |
167 | - if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) return true; |
|
199 | + if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) { |
|
200 | + return true; |
|
201 | + } |
|
168 | 202 | $query = "SELECT 1 + 1"; |
169 | - if ($this->db === null) return false; |
|
203 | + if ($this->db === null) { |
|
204 | + return false; |
|
205 | + } |
|
170 | 206 | try { |
171 | 207 | $sum = @$this->db->query($query); |
172 | 208 | if ($sum instanceof \PDOStatement) { |
173 | 209 | $sum = $sum->fetchColumn(0); |
174 | - } else $sum = 0; |
|
210 | + } else { |
|
211 | + $sum = 0; |
|
212 | + } |
|
175 | 213 | if (intval($sum) !== 2) { |
176 | 214 | return false; |
177 | 215 | } |
@@ -206,8 +244,9 @@ discard block |
||
206 | 244 | $nb = $results->fetchAll(PDO::FETCH_ASSOC); |
207 | 245 | if($nb[0]['nb'] > 0) { |
208 | 246 | return true; |
247 | + } else { |
|
248 | + return false; |
|
209 | 249 | } |
210 | - else return false; |
|
211 | 250 | } |
212 | 251 | |
213 | 252 | /* |
@@ -257,9 +296,12 @@ discard block |
||
257 | 296 | } |
258 | 297 | $result = $sth->fetch(PDO::FETCH_ASSOC); |
259 | 298 | $sth->closeCursor(); |
260 | - if ($result['nb'] > 0) return true; |
|
261 | - else return false; |
|
262 | -/* } else { |
|
299 | + if ($result['nb'] > 0) { |
|
300 | + return true; |
|
301 | + } else { |
|
302 | + return false; |
|
303 | + } |
|
304 | + /* } else { |
|
263 | 305 | $query = "SELECT * FROM ".$table." LIMIT 0"; |
264 | 306 | try { |
265 | 307 | $results = $this->db->query($query); |
@@ -298,7 +340,9 @@ discard block |
||
298 | 340 | $sth->closeCursor(); |
299 | 341 | return $result['value']; |
300 | 342 | } |
301 | - } else return $version; |
|
343 | + } else { |
|
344 | + return $version; |
|
345 | + } |
|
302 | 346 | } |
303 | 347 | |
304 | 348 | /* |
@@ -307,9 +351,14 @@ discard block |
||
307 | 351 | */ |
308 | 352 | public function latest() { |
309 | 353 | global $globalNoDB; |
310 | - if (isset($globalNoDB) && $globalNoDB === TRUE) return true; |
|
311 | - if ($this->check_schema_version() == $this->latest_schema) return true; |
|
312 | - else return false; |
|
354 | + if (isset($globalNoDB) && $globalNoDB === TRUE) { |
|
355 | + return true; |
|
356 | + } |
|
357 | + if ($this->check_schema_version() == $this->latest_schema) { |
|
358 | + return true; |
|
359 | + } else { |
|
360 | + return false; |
|
361 | + } |
|
313 | 362 | } |
314 | 363 | |
315 | 364 | } |