@@ -1,19 +1,19 @@ 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 = 34; |
| 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; |
| 11 | 11 | if ($dbc === null) { |
| 12 | 12 | if ($this->db === null && $dbname === null) { |
| 13 | 13 | if ($user === null && $pass === null) { |
| 14 | 14 | $this->createDBConnection(); |
| 15 | 15 | } else { |
| 16 | - $this->createDBConnection(null,$user,$pass); |
|
| 16 | + $this->createDBConnection(null, $user, $pass); |
|
| 17 | 17 | } |
| 18 | 18 | } else { |
| 19 | 19 | $this->createDBConnection($dbname); |
@@ -91,14 +91,14 @@ discard block |
||
| 91 | 91 | while (true) { |
| 92 | 92 | try { |
| 93 | 93 | if ($globalDBSdriver == 'mysql') { |
| 94 | - $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser, $globalDBSpass); |
|
| 94 | + $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser, $globalDBSpass); |
|
| 95 | 95 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
| 96 | 96 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 97 | - $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); |
|
| 97 | + $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); |
|
| 102 | 102 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
| 103 | 103 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); |
| 104 | 104 | // Workaround against "ONLY_FULL_GROUP_BY" mode |
@@ -108,19 +108,19 @@ discard block |
||
| 108 | 108 | $this->dbs[$DBname]->exec('SET SESSION time_zone = "+00:00"'); |
| 109 | 109 | //$this->dbs[$DBname]->exec('SET @@session.time_zone = "+00:00"'); |
| 110 | 110 | } else { |
| 111 | - $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser, $globalDBSpass); |
|
| 111 | + $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser, $globalDBSpass); |
|
| 112 | 112 | //$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
| 113 | 113 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 114 | - $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); |
|
| 114 | + $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); |
|
| 119 | 119 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
| 120 | 120 | $this->dbs[$DBname]->exec('SET timezone="UTC"'); |
| 121 | 121 | } |
| 122 | 122 | break; |
| 123 | - } catch(PDOException $e) { |
|
| 123 | + } catch (PDOException $e) { |
|
| 124 | 124 | $i++; |
| 125 | 125 | if (isset($globalDebug) && $globalDebug) echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n"; |
| 126 | 126 | //exit; |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | try { |
| 145 | 145 | //$Connection = new Connection(); |
| 146 | 146 | $results = $this->db->query($query); |
| 147 | - } catch(PDOException $e) { |
|
| 147 | + } catch (PDOException $e) { |
|
| 148 | 148 | return false; |
| 149 | 149 | } |
| 150 | - if($results->rowCount()>0) { |
|
| 150 | + if ($results->rowCount() > 0) { |
|
| 151 | 151 | return true; |
| 152 | 152 | } |
| 153 | 153 | else return false; |
@@ -168,8 +168,8 @@ discard block |
||
| 168 | 168 | return false; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - } catch(PDOException $e) { |
|
| 172 | - if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) { |
|
| 171 | + } catch (PDOException $e) { |
|
| 172 | + if ($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) { |
|
| 173 | 173 | throw $e; |
| 174 | 174 | } |
| 175 | 175 | //echo 'error ! '.$e->getMessage(); |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | /* |
| 182 | 182 | * Check if index exist |
| 183 | 183 | */ |
| 184 | - public function indexExists($table,$index) |
|
| 184 | + public function indexExists($table, $index) |
|
| 185 | 185 | { |
| 186 | 186 | global $globalDBdriver, $globalDBname; |
| 187 | 187 | if ($globalDBdriver == 'mysql') { |
@@ -192,11 +192,11 @@ discard block |
||
| 192 | 192 | try { |
| 193 | 193 | //$Connection = new Connection(); |
| 194 | 194 | $results = $this->db->query($query); |
| 195 | - } catch(PDOException $e) { |
|
| 195 | + } catch (PDOException $e) { |
|
| 196 | 196 | return false; |
| 197 | 197 | } |
| 198 | 198 | $nb = $results->fetchAll(PDO::FETCH_ASSOC); |
| 199 | - if($nb[0]['nb'] > 0) { |
|
| 199 | + if ($nb[0]['nb'] > 0) { |
|
| 200 | 200 | return true; |
| 201 | 201 | } |
| 202 | 202 | else return false; |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | $query = "SELECT * FROM ".$table." LIMIT 0"; |
| 212 | 212 | try { |
| 213 | 213 | $results = $this->db->query($query); |
| 214 | - } catch(PDOException $e) { |
|
| 214 | + } catch (PDOException $e) { |
|
| 215 | 215 | return "error : ".$e->getMessage()."\n"; |
| 216 | 216 | } |
| 217 | 217 | $columns = array(); |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | * Check if a column name exist in a table |
| 228 | 228 | * @return Boolean column exist or not |
| 229 | 229 | */ |
| 230 | - public function checkColumnName($table,$name) |
|
| 230 | + public function checkColumnName($table, $name) |
|
| 231 | 231 | { |
| 232 | 232 | global $globalDBdriver, $globalDBname; |
| 233 | 233 | if ($globalDBdriver == 'mysql') { |
@@ -237,8 +237,8 @@ discard block |
||
| 237 | 237 | } |
| 238 | 238 | try { |
| 239 | 239 | $sth = $this->db()->prepare($query); |
| 240 | - $sth->execute(array(':database' => $globalDBname,':table' => $table,':name' => $name)); |
|
| 241 | - } catch(PDOException $e) { |
|
| 240 | + $sth->execute(array(':database' => $globalDBname, ':table' => $table, ':name' => $name)); |
|
| 241 | + } catch (PDOException $e) { |
|
| 242 | 242 | echo "error : ".$e->getMessage()."\n"; |
| 243 | 243 | } |
| 244 | 244 | $result = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | try { |
| 278 | 278 | $sth = $this->db->prepare($query); |
| 279 | 279 | $sth->execute(); |
| 280 | - } catch(PDOException $e) { |
|
| 280 | + } catch (PDOException $e) { |
|
| 281 | 281 | return "error : ".$e->getMessage()."\n"; |
| 282 | 282 | } |
| 283 | 283 | $result = $sth->fetch(PDO::FETCH_ASSOC); |