Completed
Push — master ( 3474b8...2a4221 )
by Yannick
08:49
created
require/class.Connection.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.