@@ -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; |
@@ -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 | } |