Completed
Push — master ( d8c574...a11679 )
by Yannick
07:12
created
require/class.Connection.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -7,18 +7,18 @@  discard block
 block discarded – undo
7 7
 	public $latest_schema = 23;
8 8
 	
9 9
 	public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) {
10
-	    global $globalDBdriver;
11
-	    if ($dbc === null) {
10
+		global $globalDBdriver;
11
+		if ($dbc === null) {
12 12
 		if ($this->db === null && $dbname === null) {
13
-		    if ($user === null && $pass === null) {
13
+			if ($user === null && $pass === null) {
14 14
 			$this->createDBConnection();
15
-		    } else {
15
+			} else {
16 16
 			$this->createDBConnection(null,$user,$pass);
17
-		    }
17
+			}
18 18
 		} else {
19
-		    $this->createDBConnection($dbname);
19
+			$this->createDBConnection($dbname);
20 20
 		}
21
-	    } elseif ($dbname === null || $dbname === 'default') {
21
+		} elseif ($dbname === null || $dbname === 'default') {
22 22
 		$this->db = $dbc;
23 23
 		if ($this->connectionExists() === false) {
24 24
 			/*
@@ -28,19 +28,19 @@  discard block
 block discarded – undo
28 28
 			*/
29 29
 			$this->createDBConnection();
30 30
 		}
31
-	    } else {
31
+		} else {
32 32
 		//$this->connectionExists();
33 33
 		$this->dbs[$dbname] = $dbc;
34
-	    }
34
+		}
35 35
 	}
36 36
 
37 37
 
38 38
 	/**
39
-	* Creates the database connection
40
-	*
41
-	* @return Boolean of the database connection
42
-	*
43
-	*/
39
+	 * Creates the database connection
40
+	 *
41
+	 * @return Boolean of the database connection
42
+	 *
43
+	 */
44 44
 
45 45
 	public function createDBConnection($DBname = null, $user = null, $pass = null)
46 46
 	{
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 			return false;
134 134
 		}
135 135
 		if($results->rowCount()>0) {
136
-		    return true; 
136
+			return true; 
137 137
 		}
138 138
 		else return false;
139 139
 	}
@@ -150,14 +150,14 @@  discard block
 block discarded – undo
150 150
 				$sum = $sum->fetchColumn(0);
151 151
 			} else $sum = 0;
152 152
 			if (intval($sum) !== 2) {
153
-			     return false;
153
+				 return false;
154 154
 			}
155 155
 			
156 156
 		} catch(PDOException $e) {
157 157
 			if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
158
-            			throw $e;
159
-	                }
160
-	                //echo 'error ! '.$e->getMessage();
158
+						throw $e;
159
+					}
160
+					//echo 'error ! '.$e->getMessage();
161 161
 			return false;
162 162
 		}
163 163
 		return true; 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 			return false;
182 182
 		}
183 183
 		if($results->rowCount()>0) {
184
-		    return true; 
184
+			return true; 
185 185
 		}
186 186
 		else return false;
187 187
 	}
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
 		$version = 0;
236 236
 		if ($this->tableExists('aircraft')) {
237 237
 			if (!$this->tableExists('config')) {
238
-	    			$version = '1';
239
-	    			return $version;
238
+					$version = '1';
239
+					return $version;
240 240
 			} else {
241 241
 				$Connection = new Connection();
242 242
 				$query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
 	* @return Boolean if latest version or not
258 258
 	*/
259 259
 	public function latest() {
260
-	    if ($this->check_schema_version() == $this->latest_schema) return true;
261
-	    else return false;
260
+		if ($this->check_schema_version() == $this->latest_schema) return true;
261
+		else return false;
262 262
 	}
263 263
 
264 264
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  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 = 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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.