Completed
Push — master ( 152aae...0c8619 )
by Yannick
05:26
created
require/class.Connection.php 1 patch
Spacing   +28 added lines, -28 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 = 26;
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);
@@ -91,14 +91,14 @@  discard block
 block discarded – undo
91 91
 		while (true) {
92 92
 			try {
93 93
 				if ($globalDBSdriver == 'mysql') {
94
-					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser,  $globalDBSpass);
94
+					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser, $globalDBSpass);
95 95
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
96 96
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
97
-					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
98
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500);
99
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
100
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
101
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
97
+					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
98
+					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 500);
99
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut);
100
+					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true);
101
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent);
102 102
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
103 103
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
104 104
 					// Workaround against "ONLY_FULL_GROUP_BY" mode
@@ -108,18 +108,18 @@  discard block
 block discarded – undo
108 108
 					$this->dbs[$DBname]->exec('SET SESSION time_zone = "+00:00"');
109 109
 					//$this->dbs[$DBname]->exec('SET @@session.time_zone = "+00:00"');
110 110
 				} else {
111
-					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser,  $globalDBSpass);
111
+					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser, $globalDBSpass);
112 112
 					//$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
113 113
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
114
-					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
115
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
116
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
117
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
118
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
114
+					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
115
+					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 200);
116
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut);
117
+					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true);
118
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent);
119 119
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
120 120
 				}
121 121
 				break;
122
-			} catch(PDOException $e) {
122
+			} catch (PDOException $e) {
123 123
 				$i++;
124 124
 				if (isset($globalDebug) && $globalDebug) echo $e->getMessage()."\n";
125 125
 				//exit;
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
 		try {
144 144
 			//$Connection = new Connection();
145 145
 			$results = $this->db->query($query);
146
-		} catch(PDOException $e) {
146
+		} catch (PDOException $e) {
147 147
 			return false;
148 148
 		}
149
-		if($results->rowCount()>0) {
149
+		if ($results->rowCount() > 0) {
150 150
 		    return true; 
151 151
 		}
152 152
 		else return false;
@@ -167,8 +167,8 @@  discard block
 block discarded – undo
167 167
 			     return false;
168 168
 			}
169 169
 			
170
-		} catch(PDOException $e) {
171
-			if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
170
+		} catch (PDOException $e) {
171
+			if ($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
172 172
             			throw $e;
173 173
 	                }
174 174
 	                //echo 'error ! '.$e->getMessage();
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	/*
181 181
 	* Check if index exist
182 182
 	*/
183
-	public function indexExists($table,$index)
183
+	public function indexExists($table, $index)
184 184
 	{
185 185
 		global $globalDBdriver, $globalDBname;
186 186
 		if ($globalDBdriver == 'mysql') {
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
 		try {
192 192
 			//$Connection = new Connection();
193 193
 			$results = $this->db->query($query);
194
-		} catch(PDOException $e) {
194
+		} catch (PDOException $e) {
195 195
 			return false;
196 196
 		}
197 197
 		$nb = $results->fetchAll(PDO::FETCH_ASSOC);
198
-		if($nb[0]['nb'] > 0) {
198
+		if ($nb[0]['nb'] > 0) {
199 199
 			return true; 
200 200
 		}
201 201
 		else return false;
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 		$query = "SELECT * FROM ".$table." LIMIT 0";
211 211
 		try {
212 212
 			$results = $this->db->query($query);
213
-		} catch(PDOException $e) {
213
+		} catch (PDOException $e) {
214 214
 			return "error : ".$e->getMessage()."\n";
215 215
 		}
216 216
 		$columns = array();
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 	* Check if a column name exist in a table
227 227
 	* @return Boolean column exist or not
228 228
 	*/
229
-	public function checkColumnName($table,$name)
229
+	public function checkColumnName($table, $name)
230 230
 	{
231 231
 		global $globalDBdriver, $globalDBname;
232 232
 		if ($globalDBdriver == 'mysql') {
@@ -236,8 +236,8 @@  discard block
 block discarded – undo
236 236
 		}
237 237
 			try {
238 238
 				$sth = $this->db()->prepare($query);
239
-				$sth->execute(array(':database' => $globalDBname,':table' => $table,':name' => $name));
240
-			} catch(PDOException $e) {
239
+				$sth->execute(array(':database' => $globalDBname, ':table' => $table, ':name' => $name));
240
+			} catch (PDOException $e) {
241 241
 				echo "error : ".$e->getMessage()."\n";
242 242
 			}
243 243
 			$result = $sth->fetch(PDO::FETCH_ASSOC);
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 				try {
277 277
 					$sth = $this->db->prepare($query);
278 278
 					$sth->execute();
279
-				} catch(PDOException $e) {
279
+				} catch (PDOException $e) {
280 280
 					return "error : ".$e->getMessage()."\n";
281 281
 				}
282 282
 				$result = $sth->fetch(PDO::FETCH_ASSOC);
Please login to merge, or discard this patch.