Completed
Push — master ( d8c574...a11679 )
by Yannick
07:12
created
require/class.Connection.php 3 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.
Braces   +74 added lines, -28 removed lines patch added patch discarded remove patch
@@ -53,8 +53,11 @@  discard block
 block discarded – undo
53 53
 				$globalDBSname = $globalDBname;
54 54
 				$globalDBSuser = $globalDBuser;
55 55
 				$globalDBSpass = $globalDBpass;
56
-				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport = '') $globalDBSport = 3306;
57
-				else $globalDBSport = intval($globalDBport);
56
+				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport = '') {
57
+					$globalDBSport = 3306;
58
+				} else {
59
+					$globalDBSport = intval($globalDBport);
60
+				}
58 61
 			} else {
59 62
 				$DBname = 'default';
60 63
 				$globalDBSdriver = $globalDBdriver;
@@ -62,8 +65,11 @@  discard block
 block discarded – undo
62 65
 				$globalDBSname = $globalDBname;
63 66
 				$globalDBSuser = $user;
64 67
 				$globalDBSpass = $pass;
65
-				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport = '') $globalDBSport = 3306;
66
-				else $globalDBSport = intval($globalDBport);
68
+				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport = '') {
69
+					$globalDBSport = 3306;
70
+				} else {
71
+					$globalDBSport = intval($globalDBport);
72
+				}
67 73
 			}
68 74
 		} else {
69 75
 			$globalDBSdriver = $globalDB[$DBname]['driver'];
@@ -71,11 +77,16 @@  discard block
 block discarded – undo
71 77
 			$globalDBSname = $globalDB[$DBname]['name'];
72 78
 			$globalDBSuser = $globalDB[$DBname]['user'];
73 79
 			$globalDBSpass = $globalDB[$DBname]['pass'];
74
-			if (isset($globalDB[$DBname]['port'])) $globalDBSport = intval($globalDB[$DBname]['port']);
75
-			else $globalDBSport = 3306;
80
+			if (isset($globalDB[$DBname]['port'])) {
81
+				$globalDBSport = intval($globalDB[$DBname]['port']);
82
+			} else {
83
+				$globalDBSport = 3306;
84
+			}
76 85
 		}
77 86
 		// Set number of try to connect to DB
78
-		if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) $globalDBretry = 5;
87
+		if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) {
88
+			$globalDBretry = 5;
89
+		}
79 90
 		$i = 0;
80 91
 		while (true) {
81 92
 			try {
@@ -84,10 +95,16 @@  discard block
 block discarded – undo
84 95
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
85 96
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
86 97
 					$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);
98
+					if (!isset($globalDBTimeOut)) {
99
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
100
+					} else {
101
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
102
+					}
103
+					if (!isset($globalDBPersistent)) {
104
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
105
+					} else {
106
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
107
+					}
91 108
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
92 109
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
93 110
 					// Workaround against "ONLY_FULL_GROUP_BY" mode
@@ -98,22 +115,34 @@  discard block
 block discarded – undo
98 115
 					//$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
99 116
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
100 117
 					$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);
118
+					if (!isset($globalDBTimeOut)) {
119
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
120
+					} else {
121
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
122
+					}
123
+					if (!isset($globalDBPersistent)) {
124
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
125
+					} else {
126
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
127
+					}
105 128
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
106 129
 				}
107 130
 				break;
108 131
 			} catch(PDOException $e) {
109 132
 				$i++;
110
-				if (isset($globalDebug) && $globalDebug) echo $e->getMessage()."\n";
133
+				if (isset($globalDebug) && $globalDebug) {
134
+					echo $e->getMessage()."\n";
135
+				}
111 136
 				//exit;
112
-				if ($i > $globalDBretry) return false;
137
+				if ($i > $globalDBretry) {
138
+					return false;
139
+				}
113 140
 				//return false;
114 141
 			}
115 142
 		}
116
-		if ($DBname === 'default') $this->db = $this->dbs['default'];
143
+		if ($DBname === 'default') {
144
+			$this->db = $this->dbs['default'];
145
+		}
117 146
 		return true;
118 147
 	}
119 148
 
@@ -125,7 +154,9 @@  discard block
 block discarded – undo
125 154
 		} elseif ($globalDBdriver == 'pgsql') {
126 155
 			$query = "SELECT * FROM pg_catalog.pg_tables WHERE tablename = '".$table."'";
127 156
 		}
128
-		if ($this->db == NULL) return false;
157
+		if ($this->db == NULL) {
158
+			return false;
159
+		}
129 160
 		try {
130 161
 			//$Connection = new Connection();
131 162
 			$results = $this->db->query($query);
@@ -134,21 +165,28 @@  discard block
 block discarded – undo
134 165
 		}
135 166
 		if($results->rowCount()>0) {
136 167
 		    return true; 
168
+		} else {
169
+			return false;
137 170
 		}
138
-		else return false;
139 171
 	}
140 172
 
141 173
 	public function connectionExists()
142 174
 	{
143 175
 		global $globalDBdriver, $globalDBCheckConnection;
144
-		if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) return true;
176
+		if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) {
177
+			return true;
178
+		}
145 179
 		$query = "SELECT 1 + 1";
146
-		if ($this->db == NULL) return false;
180
+		if ($this->db == NULL) {
181
+			return false;
182
+		}
147 183
 		try {
148 184
 			$sum = @$this->db->query($query);
149 185
 			if ($sum instanceof \PDOStatement) {
150 186
 				$sum = $sum->fetchColumn(0);
151
-			} else $sum = 0;
187
+			} else {
188
+				$sum = 0;
189
+			}
152 190
 			if (intval($sum) !== 2) {
153 191
 			     return false;
154 192
 			}
@@ -182,8 +220,9 @@  discard block
 block discarded – undo
182 220
 		}
183 221
 		if($results->rowCount()>0) {
184 222
 		    return true; 
223
+		} else {
224
+			return false;
185 225
 		}
186
-		else return false;
187 226
 	}
188 227
 
189 228
 	/*
@@ -222,7 +261,9 @@  discard block
 block discarded – undo
222 261
 		$colcnt = $results->columnCount();
223 262
 		for ($i = 0; $i < $colcnt; $i++) {
224 263
 			$col = $results->getColumnMeta($i);
225
-			if ($name == $col['name']) return true;
264
+			if ($name == $col['name']) {
265
+				return true;
266
+			}
226 267
 		}
227 268
 		return false;
228 269
 	}
@@ -249,7 +290,9 @@  discard block
 block discarded – undo
249 290
 				$result = $sth->fetch(PDO::FETCH_ASSOC);
250 291
 				return $result['value'];
251 292
 			}
252
-		} else return $version;
293
+		} else {
294
+			return $version;
295
+		}
253 296
 	}
254 297
 	
255 298
 	/*
@@ -257,8 +300,11 @@  discard block
 block discarded – undo
257 300
 	* @return Boolean if latest version or not
258 301
 	*/
259 302
 	public function latest() {
260
-	    if ($this->check_schema_version() == $this->latest_schema) return true;
261
-	    else return false;
303
+	    if ($this->check_schema_version() == $this->latest_schema) {
304
+	    	return true;
305
+	    } else {
306
+	    	return false;
307
+	    }
262 308
 	}
263 309
 
264 310
 }
Please login to merge, or discard this patch.