Completed
Push — master ( 26c785...3bf766 )
by Joe
06:06
created
src/Pgsql/Db.php 1 patch
Braces   +25 added lines, -50 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@  discard block
 block discarded – undo
17 17
  *
18 18
  * @access public
19 19
  */
20
-class Db extends Generic implements Db_Interface
21
-{
20
+class Db extends Generic implements Db_Interface {
22 21
 	/* public: this is an api revision, not a CVS revision. */
23 22
 	public $type = 'pgsql';
24 23
 	public $port = '';
@@ -33,8 +32,7 @@  discard block
 block discarded – undo
33 32
 	 * @param false|string $quote optional indicate the value needs quoted
34 33
 	 * @return string
35 34
 	 */
36
-	public function ifadd($add, $me, $quote = false)
37
-	{
35
+	public function ifadd($add, $me, $quote = false) {
38 36
 		if ('' != $add) {
39 37
 			return ' '.$me.($quote === false ? '' : $quote).$add.($quote === false ? '' : $quote);
40 38
 		}
@@ -45,8 +43,7 @@  discard block
 block discarded – undo
45 43
 	 * @param $string
46 44
 	 * @return string
47 45
 	 */
48
-	public function real_escape($string = '')
49
-	{
46
+	public function real_escape($string = '') {
50 47
 		return $this->escape($string);
51 48
 	}
52 49
 
@@ -56,8 +53,7 @@  discard block
 block discarded – undo
56 53
 	 * @param string $database the name of the database to use
57 54
 	 * @return void
58 55
 	 */
59
-	public function useDb($database)
60
-	{
56
+	public function useDb($database) {
61 57
 		$this->selectDb($database);
62 58
 	}
63 59
 
@@ -67,8 +63,7 @@  discard block
 block discarded – undo
67 63
 	 * @param string $database the name of the database to use
68 64
 	 * @return void
69 65
 	 */
70
-	public function selectDb($database)
71
-	{
66
+	public function selectDb($database) {
72 67
 		/*if ($database != $this->database) {
73 68
 			$this->database = $database;
74 69
 			$this->linkId = null;
@@ -80,8 +75,7 @@  discard block
 block discarded – undo
80 75
 	 * Db::connect()
81 76
 	 * @return void
82 77
 	 */
83
-	public function connect()
84
-	{
78
+	public function connect() {
85 79
 		if (0 == $this->linkId) {
86 80
 			$connectString = trim($this->ifadd($this->host, 'host=').
87 81
 							 $this->ifadd($this->port, 'port=').
@@ -101,8 +95,7 @@  discard block
 block discarded – undo
101 95
 	 * Db::disconnect()
102 96
 	 * @return bool
103 97
 	 */
104
-	public function disconnect()
105
-	{
98
+	public function disconnect() {
106 99
 		return @pg_close($this->linkId);
107 100
 	}
108 101
 
@@ -117,8 +110,7 @@  discard block
 block discarded – undo
117 110
 	 * @param string $file optionally pass __FILE__ calling the query for logging
118 111
 	 * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
119 112
 	 */
120
-	public function queryReturn($query, $line = '', $file = '')
121
-	{
113
+	public function queryReturn($query, $line = '', $file = '') {
122 114
 		$this->query($query, $line, $file);
123 115
 		if ($this->num_rows() == 0) {
124 116
 			return false;
@@ -144,8 +136,7 @@  discard block
 block discarded – undo
144 136
 	 * @param string $file optionally pass __FILE__ calling the query for logging
145 137
 	 * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
146 138
 	 */
147
-	public function qr($query, $line = '', $file = '')
148
-	{
139
+	public function qr($query, $line = '', $file = '') {
149 140
 		return $this->queryReturn($query, $line, $file);
150 141
 	}
151 142
 
@@ -159,8 +150,7 @@  discard block
 block discarded – undo
159 150
 	 * @param string $file
160 151
 	 * @return mixed 0 if no query or query id handler, safe to ignore this return
161 152
 	 */
162
-	public function query($queryString, $line = '', $file = '')
163
-	{
153
+	public function query($queryString, $line = '', $file = '') {
164 154
 		/* No empty queries, please, since PHP4 chokes on them. */
165 155
 		/* The empty query string is passed on from the constructor,
166 156
 		* when calling the class without a query, e.g. in situations
@@ -191,8 +181,7 @@  discard block
 block discarded – undo
191 181
 	 *
192 182
 	 * @return void
193 183
 	 */
194
-	public function free()
195
-	{
184
+	public function free() {
196 185
 		@pg_freeresult($this->queryId);
197 186
 		$this->queryId = 0;
198 187
 	}
@@ -202,8 +191,7 @@  discard block
 block discarded – undo
202 191
 	 * @param mixed $resultType
203 192
 	 * @return bool
204 193
 	 */
205
-	public function next_record($resultType = PGSQL_BOTH)
206
-	{
194
+	public function next_record($resultType = PGSQL_BOTH) {
207 195
 		$this->Record = @pg_fetch_array($this->queryId, $this->Row++, $resultType);
208 196
 
209 197
 		$this->Error = pg_errormessage($this->linkId);
@@ -223,8 +211,7 @@  discard block
 block discarded – undo
223 211
 	 * @param mixed $pos
224 212
 	 * @return void
225 213
 	 */
226
-	public function seek($pos)
227
-	{
214
+	public function seek($pos) {
228 215
 		$this->Row = $pos;
229 216
 	}
230 217
 
@@ -233,8 +220,7 @@  discard block
 block discarded – undo
233 220
 	 *
234 221
 	 * @return mixed
235 222
 	 */
236
-	public function transactionBegin()
237
-	{
223
+	public function transactionBegin() {
238 224
 		return $this->query('begin');
239 225
 	}
240 226
 
@@ -242,8 +228,7 @@  discard block
 block discarded – undo
242 228
 	 * Db::transactionCommit()
243 229
 	 * @return bool|mixed
244 230
 	 */
245
-	public function transactionCommit()
246
-	{
231
+	public function transactionCommit() {
247 232
 		if (!$this->Errno) {
248 233
 			return pg_exec($this->linkId, 'commit');
249 234
 		} else {
@@ -255,8 +240,7 @@  discard block
 block discarded – undo
255 240
 	 * Db::transactionAbort()
256 241
 	 * @return mixed
257 242
 	 */
258
-	public function transactionAbort()
259
-	{
243
+	public function transactionAbort() {
260 244
 		return pg_exec($this->linkId, 'rollback');
261 245
 	}
262 246
 
@@ -266,8 +250,7 @@  discard block
 block discarded – undo
266 250
 	 * @param mixed $field
267 251
 	 * @return int
268 252
 	 */
269
-	public function getLastInsertId($table, $field)
270
-	{
253
+	public function getLastInsertId($table, $field) {
271 254
 		/* This will get the last insert ID created on the current connection.  Should only be called
272 255
 		* after an insert query is run on a table that has an auto incrementing field.  Of note, table
273 256
 		* and field are required because pgsql returns the last inserted OID, which is unique across
@@ -304,8 +287,7 @@  discard block
 block discarded – undo
304 287
 	 * @param string $mode
305 288
 	 * @return int|mixed
306 289
 	 */
307
-	public function lock($table, $mode = 'write')
308
-	{
290
+	public function lock($table, $mode = 'write') {
309 291
 		$result = $this->transactionBegin();
310 292
 
311 293
 		if ($mode == 'write') {
@@ -327,8 +309,7 @@  discard block
 block discarded – undo
327 309
 	 * Db::unlock()
328 310
 	 * @return bool|mixed
329 311
 	 */
330
-	public function unlock()
331
-	{
312
+	public function unlock() {
332 313
 		return $this->transactionCommit();
333 314
 	}
334 315
 
@@ -336,8 +317,7 @@  discard block
 block discarded – undo
336 317
 	 * Db::affectedRows()
337 318
 	 * @return void
338 319
 	 */
339
-	public function affectedRows()
340
-	{
320
+	public function affectedRows() {
341 321
 		return pg_cmdtuples($this->queryId);
342 322
 	}
343 323
 
@@ -345,8 +325,7 @@  discard block
 block discarded – undo
345 325
 	 * Db::num_rows()
346 326
 	 * @return int
347 327
 	 */
348
-	public function num_rows()
349
-	{
328
+	public function num_rows() {
350 329
 		return pg_numrows($this->queryId);
351 330
 	}
352 331
 
@@ -354,8 +333,7 @@  discard block
 block discarded – undo
354 333
 	 * Db::num_fields()
355 334
 	 * @return int
356 335
 	 */
357
-	public function num_fields()
358
-	{
336
+	public function num_fields() {
359 337
 		return pg_numfields($this->queryId);
360 338
 	}
361 339
 
@@ -365,8 +343,7 @@  discard block
 block discarded – undo
365 343
 	 * @param string $file
366 344
 	 * @return mixed|void
367 345
 	 */
368
-	public function haltmsg($msg, $line = '', $file = '')
369
-	{
346
+	public function haltmsg($msg, $line = '', $file = '') {
370 347
 		$this->log("Database error: $msg", $line, $file, 'error');
371 348
 		if ($this->Errno != '0' || $this->Error != '()') {
372 349
 			$this->log('PostgreSQL Error: '.pg_last_error($this->linkId), $line, $file, 'error');
@@ -379,8 +356,7 @@  discard block
 block discarded – undo
379 356
 	 *
380 357
 	 * @return array
381 358
 	 */
382
-	public function tableNames()
383
-	{
359
+	public function tableNames() {
384 360
 		$return = [];
385 361
 		$this->query("select relname from pg_class where relkind = 'r' and not relname like 'pg_%'");
386 362
 		$i = 0;
@@ -398,8 +374,7 @@  discard block
 block discarded – undo
398 374
 	 *
399 375
 	 * @return array
400 376
 	 */
401
-	public function indexNames()
402
-	{
377
+	public function indexNames() {
403 378
 		$return = [];
404 379
 		$this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname");
405 380
 		$i = 0;
Please login to merge, or discard this patch.