@@ -64,8 +64,11 @@ discard block |
||
| 64 | 64 | $globalDBSname = $globalDBname; |
| 65 | 65 | $globalDBSuser = $globalDBuser; |
| 66 | 66 | $globalDBSpass = $globalDBpass; |
| 67 | - if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') $globalDBSport = 3306; |
|
| 68 | - else $globalDBSport = $globalDBport; |
|
| 67 | + if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') { |
|
| 68 | + $globalDBSport = 3306; |
|
| 69 | + } else { |
|
| 70 | + $globalDBSport = $globalDBport; |
|
| 71 | + } |
|
| 69 | 72 | } else { |
| 70 | 73 | $DBname = 'default'; |
| 71 | 74 | $globalDBSdriver = $globalDBdriver; |
@@ -73,8 +76,11 @@ discard block |
||
| 73 | 76 | $globalDBSname = $globalDBname; |
| 74 | 77 | $globalDBSuser = $user; |
| 75 | 78 | $globalDBSpass = $pass; |
| 76 | - if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') $globalDBSport = 3306; |
|
| 77 | - else $globalDBSport = $globalDBport; |
|
| 79 | + if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') { |
|
| 80 | + $globalDBSport = 3306; |
|
| 81 | + } else { |
|
| 82 | + $globalDBSport = $globalDBport; |
|
| 83 | + } |
|
| 78 | 84 | } |
| 79 | 85 | } else { |
| 80 | 86 | $globalDBSdriver = $globalDB[$DBname]['driver']; |
@@ -82,11 +88,16 @@ discard block |
||
| 82 | 88 | $globalDBSname = $globalDB[$DBname]['name']; |
| 83 | 89 | $globalDBSuser = $globalDB[$DBname]['user']; |
| 84 | 90 | $globalDBSpass = $globalDB[$DBname]['pass']; |
| 85 | - if (isset($globalDB[$DBname]['port'])) $globalDBSport = $globalDB[$DBname]['port']; |
|
| 86 | - else $globalDBSport = 3306; |
|
| 91 | + if (isset($globalDB[$DBname]['port'])) { |
|
| 92 | + $globalDBSport = $globalDB[$DBname]['port']; |
|
| 93 | + } else { |
|
| 94 | + $globalDBSport = 3306; |
|
| 95 | + } |
|
| 87 | 96 | } |
| 88 | 97 | // Set number of try to connect to DB |
| 89 | - if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) $globalDBretry = 5; |
|
| 98 | + if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) { |
|
| 99 | + $globalDBretry = 5; |
|
| 100 | + } |
|
| 90 | 101 | $i = 0; |
| 91 | 102 | while (true) { |
| 92 | 103 | try { |
@@ -95,10 +106,16 @@ discard block |
||
| 95 | 106 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
| 96 | 107 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 97 | 108 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
| 98 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500); |
|
| 99 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
| 100 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
| 101 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
| 109 | + if (!isset($globalDBTimeOut)) { |
|
| 110 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500); |
|
| 111 | + } else { |
|
| 112 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
| 113 | + } |
|
| 114 | + if (!isset($globalDBPersistent)) { |
|
| 115 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
| 116 | + } else { |
|
| 117 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
| 118 | + } |
|
| 102 | 119 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
| 103 | 120 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); |
| 104 | 121 | // Workaround against "ONLY_FULL_GROUP_BY" mode |
@@ -112,23 +129,35 @@ discard block |
||
| 112 | 129 | //$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
| 113 | 130 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 114 | 131 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
| 115 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
| 116 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
| 117 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
| 118 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
| 132 | + if (!isset($globalDBTimeOut)) { |
|
| 133 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
| 134 | + } else { |
|
| 135 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
| 136 | + } |
|
| 137 | + if (!isset($globalDBPersistent)) { |
|
| 138 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
| 139 | + } else { |
|
| 140 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
| 141 | + } |
|
| 119 | 142 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
| 120 | 143 | $this->dbs[$DBname]->exec('SET timezone="UTC"'); |
| 121 | 144 | } |
| 122 | 145 | break; |
| 123 | 146 | } catch(PDOException $e) { |
| 124 | 147 | $i++; |
| 125 | - if (isset($globalDebug) && $globalDebug) echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n"; |
|
| 148 | + if (isset($globalDebug) && $globalDebug) { |
|
| 149 | + echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n"; |
|
| 150 | + } |
|
| 126 | 151 | //exit; |
| 127 | - if ($i > $globalDBretry) return false; |
|
| 152 | + if ($i > $globalDBretry) { |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 128 | 155 | //return false; |
| 129 | 156 | } |
| 130 | 157 | } |
| 131 | - if ($DBname === 'default') $this->db = $this->dbs['default']; |
|
| 158 | + if ($DBname === 'default') { |
|
| 159 | + $this->db = $this->dbs['default']; |
|
| 160 | + } |
|
| 132 | 161 | return true; |
| 133 | 162 | } |
| 134 | 163 | |
@@ -140,7 +169,9 @@ discard block |
||
| 140 | 169 | } else { |
| 141 | 170 | $query = "SELECT * FROM pg_catalog.pg_tables WHERE tablename = '".$table."'"; |
| 142 | 171 | } |
| 143 | - if ($this->db == NULL) return false; |
|
| 172 | + if ($this->db == NULL) { |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 144 | 175 | try { |
| 145 | 176 | //$Connection = new Connection(); |
| 146 | 177 | $results = $this->db->query($query); |
@@ -149,21 +180,28 @@ discard block |
||
| 149 | 180 | } |
| 150 | 181 | if($results->rowCount()>0) { |
| 151 | 182 | return true; |
| 183 | + } else { |
|
| 184 | + return false; |
|
| 152 | 185 | } |
| 153 | - else return false; |
|
| 154 | 186 | } |
| 155 | 187 | |
| 156 | 188 | public function connectionExists() |
| 157 | 189 | { |
| 158 | 190 | global $globalDBdriver, $globalDBCheckConnection; |
| 159 | - if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) return true; |
|
| 191 | + if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) { |
|
| 192 | + return true; |
|
| 193 | + } |
|
| 160 | 194 | $query = "SELECT 1 + 1"; |
| 161 | - if ($this->db === null) return false; |
|
| 195 | + if ($this->db === null) { |
|
| 196 | + return false; |
|
| 197 | + } |
|
| 162 | 198 | try { |
| 163 | 199 | $sum = @$this->db->query($query); |
| 164 | 200 | if ($sum instanceof \PDOStatement) { |
| 165 | 201 | $sum = $sum->fetchColumn(0); |
| 166 | - } else $sum = 0; |
|
| 202 | + } else { |
|
| 203 | + $sum = 0; |
|
| 204 | + } |
|
| 167 | 205 | if (intval($sum) !== 2) { |
| 168 | 206 | return false; |
| 169 | 207 | } |
@@ -198,8 +236,9 @@ discard block |
||
| 198 | 236 | $nb = $results->fetchAll(PDO::FETCH_ASSOC); |
| 199 | 237 | if($nb[0]['nb'] > 0) { |
| 200 | 238 | return true; |
| 239 | + } else { |
|
| 240 | + return false; |
|
| 201 | 241 | } |
| 202 | - else return false; |
|
| 203 | 242 | } |
| 204 | 243 | |
| 205 | 244 | /* |
@@ -243,9 +282,12 @@ discard block |
||
| 243 | 282 | } |
| 244 | 283 | $result = $sth->fetch(PDO::FETCH_ASSOC); |
| 245 | 284 | $sth->closeCursor(); |
| 246 | - if ($result['nb'] > 0) return true; |
|
| 247 | - else return false; |
|
| 248 | -/* } else { |
|
| 285 | + if ($result['nb'] > 0) { |
|
| 286 | + return true; |
|
| 287 | + } else { |
|
| 288 | + return false; |
|
| 289 | + } |
|
| 290 | + /* } else { |
|
| 249 | 291 | $query = "SELECT * FROM ".$table." LIMIT 0"; |
| 250 | 292 | try { |
| 251 | 293 | $results = $this->db->query($query); |
@@ -284,7 +326,9 @@ discard block |
||
| 284 | 326 | $sth->closeCursor(); |
| 285 | 327 | return $result['value']; |
| 286 | 328 | } |
| 287 | - } else return $version; |
|
| 329 | + } else { |
|
| 330 | + return $version; |
|
| 331 | + } |
|
| 288 | 332 | } |
| 289 | 333 | |
| 290 | 334 | /* |
@@ -292,8 +336,11 @@ discard block |
||
| 292 | 336 | * @return Boolean if latest version or not |
| 293 | 337 | */ |
| 294 | 338 | public function latest() { |
| 295 | - if ($this->check_schema_version() == $this->latest_schema) return true; |
|
| 296 | - else return false; |
|
| 339 | + if ($this->check_schema_version() == $this->latest_schema) { |
|
| 340 | + return true; |
|
| 341 | + } else { |
|
| 342 | + return false; |
|
| 343 | + } |
|
| 297 | 344 | } |
| 298 | 345 | |
| 299 | 346 | } |