Completed
Push — master ( 37d2ad...a3214e )
by Yannick
105:44 queued 76:40
created
require/class.Connection.php 1 patch
Braces   +83 added lines, -32 removed lines patch added patch discarded remove patch
@@ -73,8 +73,11 @@  discard block
 block discarded – undo
73 73
 				$globalDBSname = $globalDBname;
74 74
 				$globalDBSuser = $globalDBuser;
75 75
 				$globalDBSpass = $globalDBpass;
76
-				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') $globalDBSport = 3306;
77
-				else $globalDBSport = $globalDBport;
76
+				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') {
77
+					$globalDBSport = 3306;
78
+				} else {
79
+					$globalDBSport = $globalDBport;
80
+				}
78 81
 			} else {
79 82
 				$DBname = 'default';
80 83
 				$globalDBSdriver = $globalDBdriver;
@@ -82,8 +85,11 @@  discard block
 block discarded – undo
82 85
 				$globalDBSname = $globalDBname;
83 86
 				$globalDBSuser = $user;
84 87
 				$globalDBSpass = $pass;
85
-				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') $globalDBSport = 3306;
86
-				else $globalDBSport = $globalDBport;
88
+				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') {
89
+					$globalDBSport = 3306;
90
+				} else {
91
+					$globalDBSport = $globalDBport;
92
+				}
87 93
 			}
88 94
 		} else {
89 95
 			$globalDBSdriver = $globalDB[$DBname]['driver'];
@@ -91,11 +97,16 @@  discard block
 block discarded – undo
91 97
 			$globalDBSname = $globalDB[$DBname]['name'];
92 98
 			$globalDBSuser = $globalDB[$DBname]['user'];
93 99
 			$globalDBSpass = $globalDB[$DBname]['pass'];
94
-			if (isset($globalDB[$DBname]['port'])) $globalDBSport = $globalDB[$DBname]['port'];
95
-			else $globalDBSport = 3306;
100
+			if (isset($globalDB[$DBname]['port'])) {
101
+				$globalDBSport = $globalDB[$DBname]['port'];
102
+			} else {
103
+				$globalDBSport = 3306;
104
+			}
96 105
 		}
97 106
 		// Set number of try to connect to DB
98
-		if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) $globalDBretry = 10;
107
+		if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) {
108
+			$globalDBretry = 10;
109
+		}
99 110
 		$i = 0;
100 111
 		while (true) {
101 112
 			try {
@@ -104,10 +115,16 @@  discard block
 block discarded – undo
104 115
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
105 116
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
106 117
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
107
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500);
108
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
109
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
110
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
118
+					if (!isset($globalDBTimeOut)) {
119
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500);
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
+					}
111 128
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
112 129
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
113 130
 					// Workaround against "ONLY_FULL_GROUP_BY" mode
@@ -121,24 +138,36 @@  discard block
 block discarded – undo
121 138
 					//$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
122 139
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
123 140
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
124
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
125
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
126
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
127
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
141
+					if (!isset($globalDBTimeOut)) {
142
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
143
+					} else {
144
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
145
+					}
146
+					if (!isset($globalDBPersistent)) {
147
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
148
+					} else {
149
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
150
+					}
128 151
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
129 152
 					$this->dbs[$DBname]->exec('SET timezone="UTC"');
130 153
 				}
131 154
 				break;
132 155
 			} catch(PDOException $e) {
133 156
 				$i++;
134
-				if (isset($globalDebug) && $globalDebug) echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n";
157
+				if (isset($globalDebug) && $globalDebug) {
158
+					echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n";
159
+				}
135 160
 				//exit;
136
-				if ($i > $globalDBretry) return false;
161
+				if ($i > $globalDBretry) {
162
+					return false;
163
+				}
137 164
 				//return false;
138 165
 			}
139 166
 			sleep(5);
140 167
 		}
141
-		if ($DBname === 'default') $this->db = $this->dbs['default'];
168
+		if ($DBname === 'default') {
169
+			$this->db = $this->dbs['default'];
170
+		}
142 171
 		return true;
143 172
 	}
144 173
 
@@ -150,7 +179,9 @@  discard block
 block discarded – undo
150 179
 		} else {
151 180
 			$query = "SELECT * FROM pg_catalog.pg_tables WHERE tablename = '".$table."'";
152 181
 		}
153
-		if ($this->db == NULL) return false;
182
+		if ($this->db == NULL) {
183
+			return false;
184
+		}
154 185
 		try {
155 186
 			//$Connection = new Connection();
156 187
 			$results = $this->db->query($query);
@@ -159,22 +190,31 @@  discard block
 block discarded – undo
159 190
 		}
160 191
 		if($results->rowCount()>0) {
161 192
 		    return true; 
193
+		} else {
194
+			return false;
162 195
 		}
163
-		else return false;
164 196
 	}
165 197
 
166 198
 	public function connectionExists()
167 199
 	{
168 200
 		global $globalDBdriver, $globalDBCheckConnection, $globalNoDB;
169
-		if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) return true;
170
-		if (isset($globalNoDB) && $globalNoDB === TRUE) return true;
201
+		if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) {
202
+			return true;
203
+		}
204
+		if (isset($globalNoDB) && $globalNoDB === TRUE) {
205
+			return true;
206
+		}
171 207
 		$query = "SELECT 1 + 1";
172
-		if ($this->db === null) return false;
208
+		if ($this->db === null) {
209
+			return false;
210
+		}
173 211
 		try {
174 212
 			$sum = @$this->db->query($query);
175 213
 			if ($sum instanceof \PDOStatement) {
176 214
 				$sum = $sum->fetchColumn(0);
177
-			} else $sum = 0;
215
+			} else {
216
+				$sum = 0;
217
+			}
178 218
 			if (intval($sum) !== 2) {
179 219
 			     return false;
180 220
 			}
@@ -209,8 +249,9 @@  discard block
 block discarded – undo
209 249
 		$nb = $results->fetchAll(PDO::FETCH_ASSOC);
210 250
 		if($nb[0]['nb'] > 0) {
211 251
 			return true; 
252
+		} else {
253
+			return false;
212 254
 		}
213
-		else return false;
214 255
 	}
215 256
 
216 257
 	/*
@@ -260,9 +301,12 @@  discard block
 block discarded – undo
260 301
 			}
261 302
 			$result = $sth->fetch(PDO::FETCH_ASSOC);
262 303
 			$sth->closeCursor();
263
-			if ($result['nb'] > 0) return true;
264
-			else return false;
265
-/*		} else {
304
+			if ($result['nb'] > 0) {
305
+				return true;
306
+			} else {
307
+				return false;
308
+			}
309
+			/*		} else {
266 310
 			$query = "SELECT * FROM ".$table." LIMIT 0";
267 311
 			try {
268 312
 				$results = $this->db->query($query);
@@ -301,7 +345,9 @@  discard block
 block discarded – undo
301 345
 				$sth->closeCursor();
302 346
 				return $result['value'];
303 347
 			}
304
-		} else return $version;
348
+		} else {
349
+			return $version;
350
+		}
305 351
 	}
306 352
 	
307 353
 	/*
@@ -310,9 +356,14 @@  discard block
 block discarded – undo
310 356
 	*/
311 357
 	public function latest() {
312 358
 	    global $globalNoDB;
313
-	    if (isset($globalNoDB) && $globalNoDB === TRUE) return true;
314
-	    if ($this->check_schema_version() == $this->latest_schema) return true;
315
-	    else return false;
359
+	    if (isset($globalNoDB) && $globalNoDB === TRUE) {
360
+	    	return true;
361
+	    }
362
+	    if ($this->check_schema_version() == $this->latest_schema) {
363
+	    	return true;
364
+	    } else {
365
+	    	return false;
366
+	    }
316 367
 	}
317 368
 
318 369
 }
Please login to merge, or discard this patch.