@@ -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 = 23; |
| 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); |
@@ -80,32 +80,32 @@ discard block |
||
| 80 | 80 | while (true) { |
| 81 | 81 | try { |
| 82 | 82 | if ($globalDBSdriver == 'mysql') { |
| 83 | - $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser, $globalDBSpass); |
|
| 83 | + $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser, $globalDBSpass); |
|
| 84 | 84 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
| 85 | 85 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 86 | - $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
|
| 87 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
| 88 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
| 89 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
| 90 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
| 86 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); |
|
| 87 | + if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 200); |
|
| 88 | + else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut); |
|
| 89 | + if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true); |
|
| 90 | + else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent); |
|
| 91 | 91 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
| 92 | 92 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); |
| 93 | 93 | // Workaround against "ONLY_FULL_GROUP_BY" mode |
| 94 | 94 | // to enable it : $this->dbs[$DBname]->exec('SET sql_mode = "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY"'); |
| 95 | 95 | $this->dbs[$DBname]->exec('SET sql_mode = "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"'); |
| 96 | 96 | } else { |
| 97 | - $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser, $globalDBSpass); |
|
| 97 | + $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser, $globalDBSpass); |
|
| 98 | 98 | //$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
| 99 | 99 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 100 | - $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
|
| 101 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
| 102 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
| 103 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
| 104 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
| 100 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); |
|
| 101 | + if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 200); |
|
| 102 | + else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut); |
|
| 103 | + if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true); |
|
| 104 | + else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent); |
|
| 105 | 105 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
| 106 | 106 | } |
| 107 | 107 | break; |
| 108 | - } catch(PDOException $e) { |
|
| 108 | + } catch (PDOException $e) { |
|
| 109 | 109 | $i++; |
| 110 | 110 | if (isset($globalDebug) && $globalDebug) echo $e->getMessage()."\n"; |
| 111 | 111 | //exit; |
@@ -129,10 +129,10 @@ discard block |
||
| 129 | 129 | try { |
| 130 | 130 | //$Connection = new Connection(); |
| 131 | 131 | $results = $this->db->query($query); |
| 132 | - } catch(PDOException $e) { |
|
| 132 | + } catch (PDOException $e) { |
|
| 133 | 133 | return false; |
| 134 | 134 | } |
| 135 | - if($results->rowCount()>0) { |
|
| 135 | + if ($results->rowCount() > 0) { |
|
| 136 | 136 | return true; |
| 137 | 137 | } |
| 138 | 138 | else return false; |
@@ -153,8 +153,8 @@ discard block |
||
| 153 | 153 | return false; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - } catch(PDOException $e) { |
|
| 157 | - if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) { |
|
| 156 | + } catch (PDOException $e) { |
|
| 157 | + if ($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) { |
|
| 158 | 158 | throw $e; |
| 159 | 159 | } |
| 160 | 160 | //echo 'error ! '.$e->getMessage(); |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | /* |
| 167 | 167 | * Check if index exist |
| 168 | 168 | */ |
| 169 | - public function indexExists($table,$index) |
|
| 169 | + public function indexExists($table, $index) |
|
| 170 | 170 | { |
| 171 | 171 | global $globalDBdriver, $globalDBname; |
| 172 | 172 | if ($globalDBdriver == 'mysql') { |
@@ -177,10 +177,10 @@ discard block |
||
| 177 | 177 | try { |
| 178 | 178 | //$Connection = new Connection(); |
| 179 | 179 | $results = $this->db->query($query); |
| 180 | - } catch(PDOException $e) { |
|
| 180 | + } catch (PDOException $e) { |
|
| 181 | 181 | return false; |
| 182 | 182 | } |
| 183 | - if($results->rowCount()>0) { |
|
| 183 | + if ($results->rowCount() > 0) { |
|
| 184 | 184 | return true; |
| 185 | 185 | } |
| 186 | 186 | else return false; |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | $query = "SELECT * FROM ".$table." LIMIT 0"; |
| 196 | 196 | try { |
| 197 | 197 | $results = $this->db->query($query); |
| 198 | - } catch(PDOException $e) { |
|
| 198 | + } catch (PDOException $e) { |
|
| 199 | 199 | return "error : ".$e->getMessage()."\n"; |
| 200 | 200 | } |
| 201 | 201 | $columns = array(); |
@@ -211,12 +211,12 @@ discard block |
||
| 211 | 211 | * Check if a column name exist in a table |
| 212 | 212 | * @return Boolean column exist or not |
| 213 | 213 | */ |
| 214 | - public function checkColumnName($table,$name) |
|
| 214 | + public function checkColumnName($table, $name) |
|
| 215 | 215 | { |
| 216 | 216 | $query = "SELECT * FROM ".$table." LIMIT 0"; |
| 217 | 217 | try { |
| 218 | 218 | $results = $this->db->query($query); |
| 219 | - } catch(PDOException $e) { |
|
| 219 | + } catch (PDOException $e) { |
|
| 220 | 220 | return "error : ".$e->getMessage()."\n"; |
| 221 | 221 | } |
| 222 | 222 | $colcnt = $results->columnCount(); |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | try { |
| 244 | 244 | $sth = $this->db->prepare($query); |
| 245 | 245 | $sth->execute(); |
| 246 | - } catch(PDOException $e) { |
|
| 246 | + } catch (PDOException $e) { |
|
| 247 | 247 | return "error : ".$e->getMessage()."\n"; |
| 248 | 248 | } |
| 249 | 249 | $result = $sth->fetch(PDO::FETCH_ASSOC); |