Completed
Push — master ( 964a3c...d0c1c5 )
by Yannick
59:18 queued 25:03
created
require/class.Connection.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -8,12 +8,12 @@  discard block
 block discarded – undo
8 8
 */
9 9
 require_once(dirname(__FILE__).'/settings.php');
10 10
 
11
-class Connection{
11
+class Connection {
12 12
 	public $db = null;
13 13
 	public $dbs = array();
14 14
 	public $latest_schema = 55;
15 15
 
16
-	public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) {
16
+	public function __construct($dbc = null, $dbname = null, $user = null, $pass = null) {
17 17
 		global $globalNoDB;
18 18
 		if (isset($globalNoDB) && $globalNoDB === TRUE) {
19 19
 			$this->db = null;
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 					if ($user === null && $pass === null) {
24 24
 						$this->createDBConnection();
25 25
 					} else {
26
-						$this->createDBConnection(null,$user,$pass);
26
+						$this->createDBConnection(null, $user, $pass);
27 27
 					}
28 28
 				} else {
29 29
 					$this->createDBConnection($dbname);
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
 		while (true) {
108 108
 			try {
109 109
 				if ($globalDBSdriver == 'mysql') {
110
-					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser,  $globalDBSpass);
110
+					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser, $globalDBSpass);
111 111
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
112 112
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
113
-					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
114
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500);
115
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
116
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
117
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
113
+					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
114
+					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 500);
115
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut);
116
+					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true);
117
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent);
118 118
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
119 119
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
120 120
 					// Workaround against "ONLY_FULL_GROUP_BY" mode
@@ -124,19 +124,19 @@  discard block
 block discarded – undo
124 124
 					$this->dbs[$DBname]->exec('SET SESSION time_zone = "+00:00"');
125 125
 					//$this->dbs[$DBname]->exec('SET @@session.time_zone = "+00:00"');
126 126
 				} else {
127
-					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser,  $globalDBSpass);
127
+					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser, $globalDBSpass);
128 128
 					//$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
129 129
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
130
-					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
131
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
132
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
133
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
134
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
130
+					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
131
+					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 200);
132
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut);
133
+					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true);
134
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent);
135 135
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
136 136
 					$this->dbs[$DBname]->exec('SET timezone="UTC"');
137 137
 				}
138 138
 				break;
139
-			} catch(PDOException $e) {
139
+			} catch (PDOException $e) {
140 140
 				$i++;
141 141
 				if (isset($globalDebug) && $globalDebug) echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n";
142 142
 				//exit;
@@ -161,10 +161,10 @@  discard block
 block discarded – undo
161 161
 		try {
162 162
 			//$Connection = new Connection();
163 163
 			$results = $this->db->query($query);
164
-		} catch(PDOException $e) {
164
+		} catch (PDOException $e) {
165 165
 			return false;
166 166
 		}
167
-		if($results->rowCount()>0) {
167
+		if ($results->rowCount() > 0) {
168 168
 		    return true; 
169 169
 		}
170 170
 		else return false;
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 			     return false;
187 187
 			}
188 188
 			
189
-		} catch(PDOException $e) {
190
-			if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
189
+		} catch (PDOException $e) {
190
+			if ($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
191 191
             			throw $e;
192 192
 	                }
193 193
 	                //echo 'error ! '.$e->getMessage();
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	/*
200 200
 	* Check if index exist
201 201
 	*/
202
-	public function indexExists($table,$index)
202
+	public function indexExists($table, $index)
203 203
 	{
204 204
 		global $globalDBdriver, $globalDBname;
205 205
 		if ($globalDBdriver == 'mysql') {
@@ -210,11 +210,11 @@  discard block
 block discarded – undo
210 210
 		try {
211 211
 			//$Connection = new Connection();
212 212
 			$results = $this->db->query($query);
213
-		} catch(PDOException $e) {
213
+		} catch (PDOException $e) {
214 214
 			return false;
215 215
 		}
216 216
 		$nb = $results->fetchAll(PDO::FETCH_ASSOC);
217
-		if($nb[0]['nb'] > 0) {
217
+		if ($nb[0]['nb'] > 0) {
218 218
 			return true; 
219 219
 		}
220 220
 		else return false;
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		$query = "SELECT * FROM ".$table." LIMIT 0";
230 230
 		try {
231 231
 			$results = $this->db->query($query);
232
-		} catch(PDOException $e) {
232
+		} catch (PDOException $e) {
233 233
 			return "error : ".$e->getMessage()."\n";
234 234
 		}
235 235
 		$columns = array();
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 		return $columns;
242 242
 	}
243 243
 
244
-	public function getColumnType($table,$column) {
244
+	public function getColumnType($table, $column) {
245 245
 		$select = $this->db->query('SELECT '.$column.' FROM '.$table);
246 246
 		$tomet = $select->getColumnMeta(0);
247 247
 		return $tomet['native_type'];
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	* Check if a column name exist in a table
252 252
 	* @return Boolean column exist or not
253 253
 	*/
254
-	public function checkColumnName($table,$name)
254
+	public function checkColumnName($table, $name)
255 255
 	{
256 256
 		global $globalDBdriver, $globalDBname;
257 257
 		if ($globalDBdriver == 'mysql') {
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
 		}
262 262
 			try {
263 263
 				$sth = $this->db()->prepare($query);
264
-				$sth->execute(array(':database' => $globalDBname,':table' => $table,':name' => $name));
265
-			} catch(PDOException $e) {
264
+				$sth->execute(array(':database' => $globalDBname, ':table' => $table, ':name' => $name));
265
+			} catch (PDOException $e) {
266 266
 				echo "error : ".$e->getMessage()."\n";
267 267
 			}
268 268
 			$result = $sth->fetch(PDO::FETCH_ASSOC);
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 				try {
302 302
 					$sth = $this->db->prepare($query);
303 303
 					$sth->execute();
304
-				} catch(PDOException $e) {
304
+				} catch (PDOException $e) {
305 305
 					return "error : ".$e->getMessage()."\n";
306 306
 				}
307 307
 				$result = $sth->fetch(PDO::FETCH_ASSOC);
Please login to merge, or discard this patch.