Test Failed
Push — master ( 8b6eb2...d03f69 )
by Joe
17:14 queued 10:05
created
src/Pgsql/Db.php 2 patches
Indentation   +380 added lines, -380 removed lines patch added patch discarded remove patch
@@ -19,396 +19,396 @@
 block discarded – undo
19 19
  */
20 20
 class Db extends Generic implements Db_Interface
21 21
 {
22
-    /* public: this is an api revision, not a CVS revision. */
23
-    public $type = 'pgsql';
24
-    public $port = '';
25
-    public $defaultPort = '5432';
26
-
27
-
28
-    /**
29
-     * adds if not blank
30
-     *
31
-     * @param string $add the value to set
32
-     * @param string $me the key/field to set the value for
33
-     * @param false|string $quote optional indicate the value needs quoted
34
-     * @return string
35
-     */
36
-    public function ifadd($add, $me, $quote = false)
37
-    {
38
-        if ('' != $add) {
39
-            return ' '.$me.($quote === false ? '' : $quote).$add.($quote === false ? '' : $quote);
40
-        }
41
-        return '';
42
-    }
43
-
44
-    /**
45
-     * @param $string
46
-     * @return string
47
-     */
48
-    public function real_escape($string = '')
49
-    {
50
-        return $this->escape($string);
51
-    }
52
-
53
-    /**
54
-     * alias function of select_db, changes the database we are working with.
55
-     *
56
-     * @param string $database the name of the database to use
57
-     * @return void
58
-     */
59
-    public function useDb($database)
60
-    {
61
-        $this->selectDb($database);
62
-    }
63
-
64
-    /**
65
-     * changes the database we are working with.
66
-     *
67
-     * @param string $database the name of the database to use
68
-     * @return void
69
-     */
70
-    public function selectDb($database)
71
-    {
72
-        /*if ($database != $this->database) {
22
+	/* public: this is an api revision, not a CVS revision. */
23
+	public $type = 'pgsql';
24
+	public $port = '';
25
+	public $defaultPort = '5432';
26
+
27
+
28
+	/**
29
+	 * adds if not blank
30
+	 *
31
+	 * @param string $add the value to set
32
+	 * @param string $me the key/field to set the value for
33
+	 * @param false|string $quote optional indicate the value needs quoted
34
+	 * @return string
35
+	 */
36
+	public function ifadd($add, $me, $quote = false)
37
+	{
38
+		if ('' != $add) {
39
+			return ' '.$me.($quote === false ? '' : $quote).$add.($quote === false ? '' : $quote);
40
+		}
41
+		return '';
42
+	}
43
+
44
+	/**
45
+	 * @param $string
46
+	 * @return string
47
+	 */
48
+	public function real_escape($string = '')
49
+	{
50
+		return $this->escape($string);
51
+	}
52
+
53
+	/**
54
+	 * alias function of select_db, changes the database we are working with.
55
+	 *
56
+	 * @param string $database the name of the database to use
57
+	 * @return void
58
+	 */
59
+	public function useDb($database)
60
+	{
61
+		$this->selectDb($database);
62
+	}
63
+
64
+	/**
65
+	 * changes the database we are working with.
66
+	 *
67
+	 * @param string $database the name of the database to use
68
+	 * @return void
69
+	 */
70
+	public function selectDb($database)
71
+	{
72
+		/*if ($database != $this->database) {
73 73
             $this->database = $database;
74 74
             $this->linkId = null;
75 75
             $this->connect();
76 76
         }*/
77
-    }
78
-
79
-    /**
80
-     * Db::connect()
81
-     * @return void
82
-     */
83
-    public function connect()
84
-    {
85
-        if (0 == $this->linkId) {
86
-            $connectString = trim($this->ifadd($this->host, 'host=').
87
-                             $this->ifadd($this->port, 'port=').
88
-                             $this->ifadd($this->database, 'dbname=').
89
-                             $this->ifadd($this->user, 'user=').
90
-                             $this->ifadd($this->password, 'password=', "'"));
91
-            $this->linkId = pg_connect($connectString);
92
-            if (!$this->linkId) {
93
-                $this->halt('Link-ID == FALSE, connect failed');
94
-            }
95
-        }
96
-    }
97
-
98
-    /* This only affects systems not using persistent connections */
99
-
100
-    /**
101
-     * Db::disconnect()
102
-     * @return bool
103
-     */
104
-    public function disconnect()
105
-    {
106
-        return @pg_close($this->linkId);
107
-    }
108
-
109
-    /**
110
-     * Db::queryReturn()
111
-     *
112
-     * Sends an SQL query to the server like the normal query() command but iterates through
113
-     * any rows and returns the row or rows immediately or FALSE on error
114
-     *
115
-     * @param mixed $query SQL Query to be used
116
-     * @param string $line optionally pass __LINE__ calling the query for logging
117
-     * @param string $file optionally pass __FILE__ calling the query for logging
118
-     * @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
-     */
120
-    public function queryReturn($query, $line = '', $file = '')
121
-    {
122
-        $this->query($query, $line, $file);
123
-        if ($this->num_rows() == 0) {
124
-            return false;
125
-        } elseif ($this->num_rows() == 1) {
126
-            $this->next_record(MYSQL_ASSOC);
127
-            return $this->Record;
128
-        } else {
129
-            $out = [];
130
-            while ($this->next_record(MYSQL_ASSOC)) {
131
-                $out[] = $this->Record;
132
-            }
133
-            return $out;
134
-        }
135
-    }
136
-
137
-    /**
138
-     * db:qr()
139
-     *
140
-     *  alias of queryReturn()
141
-     *
142
-     * @param mixed $query SQL Query to be used
143
-     * @param string $line optionally pass __LINE__ calling the query for logging
144
-     * @param string $file optionally pass __FILE__ calling the query for logging
145
-     * @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
-     */
147
-    public function qr($query, $line = '', $file = '')
148
-    {
149
-        return $this->queryReturn($query, $line, $file);
150
-    }
151
-
152
-    /**
153
-     * Db::query()
154
-     *
155
-     *  Sends an SQL query to the database
156
-     *
157
-     * @param mixed $queryString
158
-     * @param string $line
159
-     * @param string $file
160
-     * @return mixed 0 if no query or query id handler, safe to ignore this return
161
-     */
162
-    public function query($queryString, $line = '', $file = '')
163
-    {
164
-        /* No empty queries, please, since PHP4 chokes on them. */
165
-        /* The empty query string is passed on from the constructor,
77
+	}
78
+
79
+	/**
80
+	 * Db::connect()
81
+	 * @return void
82
+	 */
83
+	public function connect()
84
+	{
85
+		if (0 == $this->linkId) {
86
+			$connectString = trim($this->ifadd($this->host, 'host=').
87
+							 $this->ifadd($this->port, 'port=').
88
+							 $this->ifadd($this->database, 'dbname=').
89
+							 $this->ifadd($this->user, 'user=').
90
+							 $this->ifadd($this->password, 'password=', "'"));
91
+			$this->linkId = pg_connect($connectString);
92
+			if (!$this->linkId) {
93
+				$this->halt('Link-ID == FALSE, connect failed');
94
+			}
95
+		}
96
+	}
97
+
98
+	/* This only affects systems not using persistent connections */
99
+
100
+	/**
101
+	 * Db::disconnect()
102
+	 * @return bool
103
+	 */
104
+	public function disconnect()
105
+	{
106
+		return @pg_close($this->linkId);
107
+	}
108
+
109
+	/**
110
+	 * Db::queryReturn()
111
+	 *
112
+	 * Sends an SQL query to the server like the normal query() command but iterates through
113
+	 * any rows and returns the row or rows immediately or FALSE on error
114
+	 *
115
+	 * @param mixed $query SQL Query to be used
116
+	 * @param string $line optionally pass __LINE__ calling the query for logging
117
+	 * @param string $file optionally pass __FILE__ calling the query for logging
118
+	 * @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
+	 */
120
+	public function queryReturn($query, $line = '', $file = '')
121
+	{
122
+		$this->query($query, $line, $file);
123
+		if ($this->num_rows() == 0) {
124
+			return false;
125
+		} elseif ($this->num_rows() == 1) {
126
+			$this->next_record(MYSQL_ASSOC);
127
+			return $this->Record;
128
+		} else {
129
+			$out = [];
130
+			while ($this->next_record(MYSQL_ASSOC)) {
131
+				$out[] = $this->Record;
132
+			}
133
+			return $out;
134
+		}
135
+	}
136
+
137
+	/**
138
+	 * db:qr()
139
+	 *
140
+	 *  alias of queryReturn()
141
+	 *
142
+	 * @param mixed $query SQL Query to be used
143
+	 * @param string $line optionally pass __LINE__ calling the query for logging
144
+	 * @param string $file optionally pass __FILE__ calling the query for logging
145
+	 * @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
+	 */
147
+	public function qr($query, $line = '', $file = '')
148
+	{
149
+		return $this->queryReturn($query, $line, $file);
150
+	}
151
+
152
+	/**
153
+	 * Db::query()
154
+	 *
155
+	 *  Sends an SQL query to the database
156
+	 *
157
+	 * @param mixed $queryString
158
+	 * @param string $line
159
+	 * @param string $file
160
+	 * @return mixed 0 if no query or query id handler, safe to ignore this return
161
+	 */
162
+	public function query($queryString, $line = '', $file = '')
163
+	{
164
+		/* No empty queries, please, since PHP4 chokes on them. */
165
+		/* The empty query string is passed on from the constructor,
166 166
         * when calling the class without a query, e.g. in situations
167 167
         * like these: '$db = new db_Subclass;'
168 168
         */
169
-        if ($queryString == '') {
170
-            return 0;
171
-        }
172
-
173
-        $this->connect();
174
-
175
-        /* printf("<br>Debug: query = %s<br>\n", $queryString); */
176
-
177
-        $this->queryId = @pg_exec($this->linkId, $queryString);
178
-        $this->Row = 0;
179
-
180
-        $this->Error = pg_errormessage($this->linkId);
181
-        $this->Errno = ($this->Error == '') ? 0 : 1;
182
-        if (!$this->queryId) {
183
-            $this->halt('Invalid SQL: '.$queryString, $line, $file);
184
-        }
185
-
186
-        return $this->queryId;
187
-    }
188
-
189
-    /**
190
-     * Db::free()
191
-     *
192
-     * @return void
193
-     */
194
-    public function free()
195
-    {
196
-        @pg_freeresult($this->queryId);
197
-        $this->queryId = 0;
198
-    }
199
-
200
-    /**
201
-     * Db::next_record()
202
-     * @param mixed $resultType
203
-     * @return bool
204
-     */
205
-    public function next_record($resultType = PGSQL_BOTH)
206
-    {
207
-        $this->Record = @pg_fetch_array($this->queryId, $this->Row++, $resultType);
208
-
209
-        $this->Error = pg_errormessage($this->linkId);
210
-        $this->Errno = ($this->Error == '') ? 0 : 1;
211
-
212
-        $stat = is_array($this->Record);
213
-        if (!$stat && $this->autoFree) {
214
-            pg_freeresult($this->queryId);
215
-            $this->queryId = 0;
216
-        }
217
-        return $stat;
218
-    }
219
-
220
-    /**
221
-     * Db::seek()
222
-     *
223
-     * @param mixed $pos
224
-     * @return void
225
-     */
226
-    public function seek($pos)
227
-    {
228
-        $this->Row = $pos;
229
-    }
230
-
231
-    /**
232
-     * Db::transactionBegin()
233
-     *
234
-     * @return mixed
235
-     */
236
-    public function transactionBegin()
237
-    {
238
-        return $this->query('begin');
239
-    }
240
-
241
-    /**
242
-     * Db::transactionCommit()
243
-     * @return bool|mixed
244
-     */
245
-    public function transactionCommit()
246
-    {
247
-        if (!$this->Errno) {
248
-            return pg_exec($this->linkId, 'commit');
249
-        } else {
250
-            return false;
251
-        }
252
-    }
253
-
254
-    /**
255
-     * Db::transactionAbort()
256
-     * @return mixed
257
-     */
258
-    public function transactionAbort()
259
-    {
260
-        return pg_exec($this->linkId, 'rollback');
261
-    }
262
-
263
-    /**
264
-     * Db::getLastInsertId()
265
-     * @param mixed $table
266
-     * @param mixed $field
267
-     * @return int
268
-     */
269
-    public function getLastInsertId($table, $field)
270
-    {
271
-        /* This will get the last insert ID created on the current connection.  Should only be called
169
+		if ($queryString == '') {
170
+			return 0;
171
+		}
172
+
173
+		$this->connect();
174
+
175
+		/* printf("<br>Debug: query = %s<br>\n", $queryString); */
176
+
177
+		$this->queryId = @pg_exec($this->linkId, $queryString);
178
+		$this->Row = 0;
179
+
180
+		$this->Error = pg_errormessage($this->linkId);
181
+		$this->Errno = ($this->Error == '') ? 0 : 1;
182
+		if (!$this->queryId) {
183
+			$this->halt('Invalid SQL: '.$queryString, $line, $file);
184
+		}
185
+
186
+		return $this->queryId;
187
+	}
188
+
189
+	/**
190
+	 * Db::free()
191
+	 *
192
+	 * @return void
193
+	 */
194
+	public function free()
195
+	{
196
+		@pg_freeresult($this->queryId);
197
+		$this->queryId = 0;
198
+	}
199
+
200
+	/**
201
+	 * Db::next_record()
202
+	 * @param mixed $resultType
203
+	 * @return bool
204
+	 */
205
+	public function next_record($resultType = PGSQL_BOTH)
206
+	{
207
+		$this->Record = @pg_fetch_array($this->queryId, $this->Row++, $resultType);
208
+
209
+		$this->Error = pg_errormessage($this->linkId);
210
+		$this->Errno = ($this->Error == '') ? 0 : 1;
211
+
212
+		$stat = is_array($this->Record);
213
+		if (!$stat && $this->autoFree) {
214
+			pg_freeresult($this->queryId);
215
+			$this->queryId = 0;
216
+		}
217
+		return $stat;
218
+	}
219
+
220
+	/**
221
+	 * Db::seek()
222
+	 *
223
+	 * @param mixed $pos
224
+	 * @return void
225
+	 */
226
+	public function seek($pos)
227
+	{
228
+		$this->Row = $pos;
229
+	}
230
+
231
+	/**
232
+	 * Db::transactionBegin()
233
+	 *
234
+	 * @return mixed
235
+	 */
236
+	public function transactionBegin()
237
+	{
238
+		return $this->query('begin');
239
+	}
240
+
241
+	/**
242
+	 * Db::transactionCommit()
243
+	 * @return bool|mixed
244
+	 */
245
+	public function transactionCommit()
246
+	{
247
+		if (!$this->Errno) {
248
+			return pg_exec($this->linkId, 'commit');
249
+		} else {
250
+			return false;
251
+		}
252
+	}
253
+
254
+	/**
255
+	 * Db::transactionAbort()
256
+	 * @return mixed
257
+	 */
258
+	public function transactionAbort()
259
+	{
260
+		return pg_exec($this->linkId, 'rollback');
261
+	}
262
+
263
+	/**
264
+	 * Db::getLastInsertId()
265
+	 * @param mixed $table
266
+	 * @param mixed $field
267
+	 * @return int
268
+	 */
269
+	public function getLastInsertId($table, $field)
270
+	{
271
+		/* This will get the last insert ID created on the current connection.  Should only be called
272 272
         * after an insert query is run on a table that has an auto incrementing field.  Of note, table
273 273
         * and field are required because pgsql returns the last inserted OID, which is unique across
274 274
         * an entire installation.  These params allow us to retrieve the sequenced field without adding
275 275
         * conditional code to the apps.
276 276
         */
277
-        if (!isset($table) || $table == '' || !isset($field) || $field == '') {
278
-            return -1;
279
-        }
280
-
281
-        $oid = pg_getlastoid($this->queryId);
282
-        if ($oid == -1) {
283
-            return -1;
284
-        }
285
-
286
-        $result = @pg_exec($this->linkId, "select $field from $table where oid=$oid");
287
-        if (!$result) {
288
-            return -1;
289
-        }
290
-
291
-        $Record = @pg_fetch_array($result, 0);
292
-        @pg_freeresult($result);
293
-        if (!is_array($Record)) /* OID not found? */
294
-        {
295
-            return -1;
296
-        }
297
-
298
-        return $Record[0];
299
-    }
300
-
301
-    /**
302
-     * Db::lock()
303
-     * @param mixed  $table
304
-     * @param string $mode
305
-     * @return int|mixed
306
-     */
307
-    public function lock($table, $mode = 'write')
308
-    {
309
-        $result = $this->transactionBegin();
310
-
311
-        if ($mode == 'write') {
312
-            if (is_array($table)) {
313
-                foreach ($table as $t) {
314
-                    $result = pg_exec($this->linkId, 'lock table '.$t[1].' in share mode');
315
-                }
316
-            } else {
317
-                $result = pg_exec($this->linkId, 'lock table '.$table.' in share mode');
318
-            }
319
-        } else {
320
-            $result = 1;
321
-        }
322
-
323
-        return $result;
324
-    }
325
-
326
-    /**
327
-     * Db::unlock()
328
-     * @return bool|mixed
329
-     */
330
-    public function unlock()
331
-    {
332
-        return $this->transactionCommit();
333
-    }
334
-
335
-    /**
336
-     * Db::affectedRows()
337
-     * @return void
338
-     */
339
-    public function affectedRows()
340
-    {
341
-        return pg_cmdtuples($this->queryId);
342
-    }
343
-
344
-    /**
345
-     * Db::num_rows()
346
-     * @return int
347
-     */
348
-    public function num_rows()
349
-    {
350
-        return pg_numrows($this->queryId);
351
-    }
352
-
353
-    /**
354
-     * Db::num_fields()
355
-     * @return int
356
-     */
357
-    public function num_fields()
358
-    {
359
-        return pg_numfields($this->queryId);
360
-    }
361
-
362
-    /**
363
-     * @param mixed $msg
364
-     * @param string $line
365
-     * @param string $file
366
-     * @return mixed|void
367
-     */
368
-    public function haltmsg($msg, $line = '', $file = '')
369
-    {
370
-        $this->log("Database error: $msg", $line, $file, 'error');
371
-        if ($this->Errno != '0' || $this->Error != '()') {
372
-            $this->log('PostgreSQL Error: '.pg_last_error($this->linkId), $line, $file, 'error');
373
-        }
374
-        $this->logBackTrace($msg, $line, $file);
375
-    }
376
-
377
-    /**
378
-     * Db::tableNames()
379
-     *
380
-     * @return array
381
-     */
382
-    public function tableNames()
383
-    {
384
-        $return = [];
385
-        $this->query("select relname from pg_class where relkind = 'r' and not relname like 'pg_%'");
386
-        $i = 0;
387
-        while ($this->next_record()) {
388
-            $return[$i]['table_name'] = $this->f(0);
389
-            $return[$i]['tablespace_name'] = $this->database;
390
-            $return[$i]['database'] = $this->database;
391
-            ++$i;
392
-        }
393
-        return $return;
394
-    }
395
-
396
-    /**
397
-     * Db::indexNames()
398
-     *
399
-     * @return array
400
-     */
401
-    public function indexNames()
402
-    {
403
-        $return = [];
404
-        $this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname");
405
-        $i = 0;
406
-        while ($this->next_record()) {
407
-            $return[$i]['index_name'] = $this->f(0);
408
-            $return[$i]['tablespace_name'] = $this->database;
409
-            $return[$i]['database'] = $this->database;
410
-            ++$i;
411
-        }
412
-        return $return;
413
-    }
277
+		if (!isset($table) || $table == '' || !isset($field) || $field == '') {
278
+			return -1;
279
+		}
280
+
281
+		$oid = pg_getlastoid($this->queryId);
282
+		if ($oid == -1) {
283
+			return -1;
284
+		}
285
+
286
+		$result = @pg_exec($this->linkId, "select $field from $table where oid=$oid");
287
+		if (!$result) {
288
+			return -1;
289
+		}
290
+
291
+		$Record = @pg_fetch_array($result, 0);
292
+		@pg_freeresult($result);
293
+		if (!is_array($Record)) /* OID not found? */
294
+		{
295
+			return -1;
296
+		}
297
+
298
+		return $Record[0];
299
+	}
300
+
301
+	/**
302
+	 * Db::lock()
303
+	 * @param mixed  $table
304
+	 * @param string $mode
305
+	 * @return int|mixed
306
+	 */
307
+	public function lock($table, $mode = 'write')
308
+	{
309
+		$result = $this->transactionBegin();
310
+
311
+		if ($mode == 'write') {
312
+			if (is_array($table)) {
313
+				foreach ($table as $t) {
314
+					$result = pg_exec($this->linkId, 'lock table '.$t[1].' in share mode');
315
+				}
316
+			} else {
317
+				$result = pg_exec($this->linkId, 'lock table '.$table.' in share mode');
318
+			}
319
+		} else {
320
+			$result = 1;
321
+		}
322
+
323
+		return $result;
324
+	}
325
+
326
+	/**
327
+	 * Db::unlock()
328
+	 * @return bool|mixed
329
+	 */
330
+	public function unlock()
331
+	{
332
+		return $this->transactionCommit();
333
+	}
334
+
335
+	/**
336
+	 * Db::affectedRows()
337
+	 * @return void
338
+	 */
339
+	public function affectedRows()
340
+	{
341
+		return pg_cmdtuples($this->queryId);
342
+	}
343
+
344
+	/**
345
+	 * Db::num_rows()
346
+	 * @return int
347
+	 */
348
+	public function num_rows()
349
+	{
350
+		return pg_numrows($this->queryId);
351
+	}
352
+
353
+	/**
354
+	 * Db::num_fields()
355
+	 * @return int
356
+	 */
357
+	public function num_fields()
358
+	{
359
+		return pg_numfields($this->queryId);
360
+	}
361
+
362
+	/**
363
+	 * @param mixed $msg
364
+	 * @param string $line
365
+	 * @param string $file
366
+	 * @return mixed|void
367
+	 */
368
+	public function haltmsg($msg, $line = '', $file = '')
369
+	{
370
+		$this->log("Database error: $msg", $line, $file, 'error');
371
+		if ($this->Errno != '0' || $this->Error != '()') {
372
+			$this->log('PostgreSQL Error: '.pg_last_error($this->linkId), $line, $file, 'error');
373
+		}
374
+		$this->logBackTrace($msg, $line, $file);
375
+	}
376
+
377
+	/**
378
+	 * Db::tableNames()
379
+	 *
380
+	 * @return array
381
+	 */
382
+	public function tableNames()
383
+	{
384
+		$return = [];
385
+		$this->query("select relname from pg_class where relkind = 'r' and not relname like 'pg_%'");
386
+		$i = 0;
387
+		while ($this->next_record()) {
388
+			$return[$i]['table_name'] = $this->f(0);
389
+			$return[$i]['tablespace_name'] = $this->database;
390
+			$return[$i]['database'] = $this->database;
391
+			++$i;
392
+		}
393
+		return $return;
394
+	}
395
+
396
+	/**
397
+	 * Db::indexNames()
398
+	 *
399
+	 * @return array
400
+	 */
401
+	public function indexNames()
402
+	{
403
+		$return = [];
404
+		$this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname");
405
+		$i = 0;
406
+		while ($this->next_record()) {
407
+			$return[$i]['index_name'] = $this->f(0);
408
+			$return[$i]['tablespace_name'] = $this->database;
409
+			$return[$i]['database'] = $this->database;
410
+			++$i;
411
+		}
412
+		return $return;
413
+	}
414 414
 }
Please login to merge, or discard this 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.
src/Loader.php 2 patches
Braces   +10 added lines, -20 removed lines patch added patch discarded remove patch
@@ -15,8 +15,7 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @package MyDb
17 17
  */
18
-class Loader
19
-{
18
+class Loader {
20 19
     /* public: connection parameters */
21 20
     public $Type = 'mysqli';
22 21
     public $host = 'localhost';
@@ -56,8 +55,7 @@  discard block
 block discarded – undo
56 55
      * @param string $host Optional The hostname where the server is, or default to localhost
57 56
      * @param string $query Optional query to perform immediately
58 57
      */
59
-    public function __construct($Type = '', $database = '', $user = '', $password = '', $host = 'localhost', $query = '')
60
-    {
58
+    public function __construct($Type = '', $database = '', $user = '', $password = '', $host = 'localhost', $query = '') {
61 59
         $this->Type = $Type;
62 60
         if (!defined('db')) {
63 61
             switch ($this->Type) {
@@ -98,24 +96,21 @@  discard block
 block discarded – undo
98 96
      * @param string $line
99 97
      * @param string $file
100 98
      */
101
-    public function log($message, $line = '', $file = '')
102
-    {
99
+    public function log($message, $line = '', $file = '') {
103 100
         error_log($message);
104 101
     }
105 102
 
106 103
     /**
107 104
      * @return int
108 105
      */
109
-    public function linkId()
110
-    {
106
+    public function linkId() {
111 107
         return $this->linkId;
112 108
     }
113 109
 
114 110
     /**
115 111
      * @return int
116 112
      */
117
-    public function queryId()
118
-    {
113
+    public function queryId() {
119 114
         return $this->queryId;
120 115
     }
121 116
 
@@ -123,8 +118,7 @@  discard block
 block discarded – undo
123 118
      * @param $str
124 119
      * @return string
125 120
      */
126
-    public function dbAddslashes($str)
127
-    {
121
+    public function dbAddslashes($str) {
128 122
         if (!isset($str) || $str == '') {
129 123
             return '';
130 124
         }
@@ -142,8 +136,7 @@  discard block
 block discarded – undo
142 136
      * @param string $file optionally pass __FILE__ calling the query for logging
143 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
144 138
      */
145
-    public function qr($query, $line = '', $file = '')
146
-    {
139
+    public function qr($query, $line = '', $file = '') {
147 140
         return $this->queryReturn($query, $line, $file);
148 141
     }
149 142
 
@@ -155,8 +148,7 @@  discard block
 block discarded – undo
155 148
      * @param string $file
156 149
      * @return void
157 150
      */
158
-    public function halt($msg, $line = '', $file = '')
159
-    {
151
+    public function halt($msg, $line = '', $file = '') {
160 152
         $this->unlock(false);
161 153
 
162 154
         if ($this->haltOnError == 'no') {
@@ -182,8 +174,7 @@  discard block
 block discarded – undo
182 174
     /**
183 175
      * @param $msg
184 176
      */
185
-    public function haltmsg($msg)
186
-    {
177
+    public function haltmsg($msg) {
187 178
         $this->log("Database error: $msg", __LINE__, __FILE__);
188 179
         if ($this->Errno != '0' || $this->Error != '()') {
189 180
             $this->log('SQL Error: '.$this->Errno.' ('.$this->Error.')', __LINE__, __FILE__);
@@ -193,8 +184,7 @@  discard block
 block discarded – undo
193 184
     /**
194 185
      * @return array
195 186
      */
196
-    public function indexNames()
197
-    {
187
+    public function indexNames() {
198 188
         return [];
199 189
     }
200 190
 }
Please login to merge, or discard this patch.
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-    /**
4
-     * Generic SQL Driver Related Functionality
5
-     * @author Joe Huss <[email protected]>
6
-     * @copyright 2025
7
-     * @package MyAdmin
8
-     * @category SQL
9
-     */
3
+	/**
4
+	 * Generic SQL Driver Related Functionality
5
+	 * @author Joe Huss <[email protected]>
6
+	 * @copyright 2025
7
+	 * @package MyAdmin
8
+	 * @category SQL
9
+	 */
10 10
 
11 11
 namespace MyDb;
12 12
 
@@ -17,184 +17,184 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Loader
19 19
 {
20
-    /* public: connection parameters */
21
-    public $Type = 'mysqli';
22
-    public $host = 'localhost';
23
-    public $database = '';
24
-    public $user = '';
25
-    public $password = '';
26
-
27
-    /* public: configuration parameters */
28
-    public $autoStripslashes = false;
29
-    public $Debug = 0; // Set to 1 for debugging messages.
30
-    public $haltOnError = 'yes'; // "yes" (halt with message), "no" (ignore errors quietly), "report" (ignore error, but spit a warning)
31
-
32
-    /* public: result array and current row number */
33
-    public $Record = [];
34
-    public $Row;
35
-
36
-    /* public: current error number and error text */
37
-    public $Errno = 0;
38
-    public $Error = '';
39
-
40
-    public $type;
41
-
42
-    /* private: link and query handles */
43
-    public $linkId = 0;
44
-    public $queryId = 0;
45
-
46
-    public $characterSet = '';
47
-    public $collation = '';
48
-
49
-    /**
50
-     * Constructs the db handler, can optionally specify connection parameters
51
-     *
52
-     * @param string $Type Optional The database type mysql/mysqli/pdo/adodb/pgsql
53
-     * @param string $database Optional The database name
54
-     * @param string $user Optional The username to connect with
55
-     * @param string $password Optional The password to use
56
-     * @param string $host Optional The hostname where the server is, or default to localhost
57
-     * @param string $query Optional query to perform immediately
58
-     */
59
-    public function __construct($Type = '', $database = '', $user = '', $password = '', $host = 'localhost', $query = '')
60
-    {
61
-        $this->Type = $Type;
62
-        if (!defined('db')) {
63
-            switch ($this->Type) {
64
-                case 'mysqli':
65
-                    include_once 'class.db_mysqli.inc.php';
66
-                    break;
67
-                case 'mysql':
68
-                    include_once 'class.db_mysql.inc.php';
69
-                    break;
70
-                case 'adodb':
71
-                    include_once 'class.db_adodb.inc.php';
72
-                    break;
73
-                case 'mdb2':
74
-                    include_once 'class.db_mdb2.inc.php';
75
-                    break;
76
-                case 'pdo':
77
-                    include_once 'class.db_pdo.inc.php';
78
-                    break;
79
-                case 'pgsql':
80
-                    include_once 'class.db_pgsql.inc.php';
81
-                    break;
82
-                default:
83
-                    $this->log('Could not find DB class '.$this->Type, __LINE__, __FILE__);
84
-                    break;
85
-            }
86
-        }
87
-        $this->database = $database;
88
-        $this->user = $user;
89
-        $this->password = $password;
90
-        $this->host = $host;
91
-        if ($query != '') {
92
-            $this->query($query);
93
-        }
94
-    }
95
-
96
-    /**
97
-     * @param        $message
98
-     * @param string $line
99
-     * @param string $file
100
-     */
101
-    public function log($message, $line = '', $file = '')
102
-    {
103
-        error_log($message);
104
-    }
105
-
106
-    /**
107
-     * @return int
108
-     */
109
-    public function linkId()
110
-    {
111
-        return $this->linkId;
112
-    }
113
-
114
-    /**
115
-     * @return int
116
-     */
117
-    public function queryId()
118
-    {
119
-        return $this->queryId;
120
-    }
121
-
122
-    /**
123
-     * @param $str
124
-     * @return string
125
-     */
126
-    public function dbAddslashes($str)
127
-    {
128
-        if (!isset($str) || $str == '') {
129
-            return '';
130
-        }
131
-
132
-        return addslashes($str);
133
-    }
134
-
135
-    /**
136
-     * db:qr()
137
-     *
138
-     *  alias of queryReturn()
139
-     *
140
-     * @param mixed $query SQL Query to be used
141
-     * @param string $line optionally pass __LINE__ calling the query for logging
142
-     * @param string $file optionally pass __FILE__ calling the query for logging
143
-     * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
144
-     */
145
-    public function qr($query, $line = '', $file = '')
146
-    {
147
-        return $this->queryReturn($query, $line, $file);
148
-    }
149
-
150
-    /**
151
-     * error handling
152
-     *
153
-     * @param mixed $msg
154
-     * @param string $line
155
-     * @param string $file
156
-     * @return void
157
-     */
158
-    public function halt($msg, $line = '', $file = '')
159
-    {
160
-        $this->unlock(false);
161
-
162
-        if ($this->haltOnError == 'no') {
163
-            return;
164
-        }
165
-        $this->haltmsg($msg);
166
-
167
-        if ($file) {
168
-            error_log("File: $file");
169
-        }
170
-        if ($line) {
171
-            error_log("Line: $line");
172
-        }
173
-        if ($this->haltOnError != 'report') {
174
-            echo '<p><b>Session halted.</b>';
175
-            // FIXME! Add check for error levels
176
-            if (isset($GLOBALS['tf'])) {
177
-                $GLOBALS['tf']->terminate();
178
-            }
179
-        }
180
-    }
181
-
182
-    /**
183
-     * @param $msg
184
-     */
185
-    public function haltmsg($msg)
186
-    {
187
-        $this->log("Database error: $msg", __LINE__, __FILE__);
188
-        if ($this->Errno != '0' || $this->Error != '()') {
189
-            $this->log('SQL Error: '.$this->Errno.' ('.$this->Error.')', __LINE__, __FILE__);
190
-        }
191
-    }
192
-
193
-    /**
194
-     * @return array
195
-     */
196
-    public function indexNames()
197
-    {
198
-        return [];
199
-    }
20
+	/* public: connection parameters */
21
+	public $Type = 'mysqli';
22
+	public $host = 'localhost';
23
+	public $database = '';
24
+	public $user = '';
25
+	public $password = '';
26
+
27
+	/* public: configuration parameters */
28
+	public $autoStripslashes = false;
29
+	public $Debug = 0; // Set to 1 for debugging messages.
30
+	public $haltOnError = 'yes'; // "yes" (halt with message), "no" (ignore errors quietly), "report" (ignore error, but spit a warning)
31
+
32
+	/* public: result array and current row number */
33
+	public $Record = [];
34
+	public $Row;
35
+
36
+	/* public: current error number and error text */
37
+	public $Errno = 0;
38
+	public $Error = '';
39
+
40
+	public $type;
41
+
42
+	/* private: link and query handles */
43
+	public $linkId = 0;
44
+	public $queryId = 0;
45
+
46
+	public $characterSet = '';
47
+	public $collation = '';
48
+
49
+	/**
50
+	 * Constructs the db handler, can optionally specify connection parameters
51
+	 *
52
+	 * @param string $Type Optional The database type mysql/mysqli/pdo/adodb/pgsql
53
+	 * @param string $database Optional The database name
54
+	 * @param string $user Optional The username to connect with
55
+	 * @param string $password Optional The password to use
56
+	 * @param string $host Optional The hostname where the server is, or default to localhost
57
+	 * @param string $query Optional query to perform immediately
58
+	 */
59
+	public function __construct($Type = '', $database = '', $user = '', $password = '', $host = 'localhost', $query = '')
60
+	{
61
+		$this->Type = $Type;
62
+		if (!defined('db')) {
63
+			switch ($this->Type) {
64
+				case 'mysqli':
65
+					include_once 'class.db_mysqli.inc.php';
66
+					break;
67
+				case 'mysql':
68
+					include_once 'class.db_mysql.inc.php';
69
+					break;
70
+				case 'adodb':
71
+					include_once 'class.db_adodb.inc.php';
72
+					break;
73
+				case 'mdb2':
74
+					include_once 'class.db_mdb2.inc.php';
75
+					break;
76
+				case 'pdo':
77
+					include_once 'class.db_pdo.inc.php';
78
+					break;
79
+				case 'pgsql':
80
+					include_once 'class.db_pgsql.inc.php';
81
+					break;
82
+				default:
83
+					$this->log('Could not find DB class '.$this->Type, __LINE__, __FILE__);
84
+					break;
85
+			}
86
+		}
87
+		$this->database = $database;
88
+		$this->user = $user;
89
+		$this->password = $password;
90
+		$this->host = $host;
91
+		if ($query != '') {
92
+			$this->query($query);
93
+		}
94
+	}
95
+
96
+	/**
97
+	 * @param        $message
98
+	 * @param string $line
99
+	 * @param string $file
100
+	 */
101
+	public function log($message, $line = '', $file = '')
102
+	{
103
+		error_log($message);
104
+	}
105
+
106
+	/**
107
+	 * @return int
108
+	 */
109
+	public function linkId()
110
+	{
111
+		return $this->linkId;
112
+	}
113
+
114
+	/**
115
+	 * @return int
116
+	 */
117
+	public function queryId()
118
+	{
119
+		return $this->queryId;
120
+	}
121
+
122
+	/**
123
+	 * @param $str
124
+	 * @return string
125
+	 */
126
+	public function dbAddslashes($str)
127
+	{
128
+		if (!isset($str) || $str == '') {
129
+			return '';
130
+		}
131
+
132
+		return addslashes($str);
133
+	}
134
+
135
+	/**
136
+	 * db:qr()
137
+	 *
138
+	 *  alias of queryReturn()
139
+	 *
140
+	 * @param mixed $query SQL Query to be used
141
+	 * @param string $line optionally pass __LINE__ calling the query for logging
142
+	 * @param string $file optionally pass __FILE__ calling the query for logging
143
+	 * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
144
+	 */
145
+	public function qr($query, $line = '', $file = '')
146
+	{
147
+		return $this->queryReturn($query, $line, $file);
148
+	}
149
+
150
+	/**
151
+	 * error handling
152
+	 *
153
+	 * @param mixed $msg
154
+	 * @param string $line
155
+	 * @param string $file
156
+	 * @return void
157
+	 */
158
+	public function halt($msg, $line = '', $file = '')
159
+	{
160
+		$this->unlock(false);
161
+
162
+		if ($this->haltOnError == 'no') {
163
+			return;
164
+		}
165
+		$this->haltmsg($msg);
166
+
167
+		if ($file) {
168
+			error_log("File: $file");
169
+		}
170
+		if ($line) {
171
+			error_log("Line: $line");
172
+		}
173
+		if ($this->haltOnError != 'report') {
174
+			echo '<p><b>Session halted.</b>';
175
+			// FIXME! Add check for error levels
176
+			if (isset($GLOBALS['tf'])) {
177
+				$GLOBALS['tf']->terminate();
178
+			}
179
+		}
180
+	}
181
+
182
+	/**
183
+	 * @param $msg
184
+	 */
185
+	public function haltmsg($msg)
186
+	{
187
+		$this->log("Database error: $msg", __LINE__, __FILE__);
188
+		if ($this->Errno != '0' || $this->Error != '()') {
189
+			$this->log('SQL Error: '.$this->Errno.' ('.$this->Error.')', __LINE__, __FILE__);
190
+		}
191
+	}
192
+
193
+	/**
194
+	 * @return array
195
+	 */
196
+	public function indexNames()
197
+	{
198
+		return [];
199
+	}
200 200
 }
Please login to merge, or discard this patch.
src/Mdb2/Db.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -20,81 +20,81 @@
 block discarded – undo
20 20
  */
21 21
 class Db extends MysqliDb implements Db_Interface
22 22
 {
23
-    public $host = 'localhost';
24
-    public $user = 'pdns';
25
-    public $password = '';
26
-    public $database = 'pdns';
27
-    public $type = 'mdb2';
28
-    public $error = false;
29
-    public $message = '';
23
+	public $host = 'localhost';
24
+	public $user = 'pdns';
25
+	public $password = '';
26
+	public $database = 'pdns';
27
+	public $type = 'mdb2';
28
+	public $error = false;
29
+	public $message = '';
30 30
 
31
-    /**
32
-     * Db::quote()
33
-     * @param string $text
34
-     * @param string $type
35
-     * @return string
36
-     */
37
-    public function quote($text = '', $type = 'text')
38
-    {
39
-        switch ($type) {
40
-            case 'text':
41
-                return "'".$this->escape($text)."'";
42
-                break;
43
-            case 'integer':
44
-                return (int) $text;
45
-                break;
46
-            default:
47
-                return $text;
48
-                break;
49
-        }
50
-    }
31
+	/**
32
+	 * Db::quote()
33
+	 * @param string $text
34
+	 * @param string $type
35
+	 * @return string
36
+	 */
37
+	public function quote($text = '', $type = 'text')
38
+	{
39
+		switch ($type) {
40
+			case 'text':
41
+				return "'".$this->escape($text)."'";
42
+				break;
43
+			case 'integer':
44
+				return (int) $text;
45
+				break;
46
+			default:
47
+				return $text;
48
+				break;
49
+		}
50
+	}
51 51
 
52
-    /**
53
-     * Db::queryOne()
54
-     *
55
-     * @param mixed $query
56
-     * @param string $line
57
-     * @param string $file
58
-     * @return bool
59
-     */
60
-    public function queryOne($query, $line = '', $file = '')
61
-    {
62
-        $this->query($query, $line, $file);
63
-        if ($this->num_rows() > 0) {
64
-            $this->next_record();
65
-            return $this->f(0);
66
-        } else {
67
-            return 0;
68
-        }
69
-    }
52
+	/**
53
+	 * Db::queryOne()
54
+	 *
55
+	 * @param mixed $query
56
+	 * @param string $line
57
+	 * @param string $file
58
+	 * @return bool
59
+	 */
60
+	public function queryOne($query, $line = '', $file = '')
61
+	{
62
+		$this->query($query, $line, $file);
63
+		if ($this->num_rows() > 0) {
64
+			$this->next_record();
65
+			return $this->f(0);
66
+		} else {
67
+			return 0;
68
+		}
69
+	}
70 70
 
71
-    /**
72
-     * Db::queryRow()
73
-     *
74
-     * @param mixed $query
75
-     * @param string $line
76
-     * @param string $file
77
-     * @return array|bool
78
-     */
79
-    public function queryRow($query, $line = '', $file = '')
80
-    {
81
-        $this->query($query, $line, $file);
82
-        if ($this->num_rows() > 0) {
83
-            $this->next_record();
84
-            return $this->Record;
85
-        } else {
86
-            return 0;
87
-        }
88
-    }
71
+	/**
72
+	 * Db::queryRow()
73
+	 *
74
+	 * @param mixed $query
75
+	 * @param string $line
76
+	 * @param string $file
77
+	 * @return array|bool
78
+	 */
79
+	public function queryRow($query, $line = '', $file = '')
80
+	{
81
+		$this->query($query, $line, $file);
82
+		if ($this->num_rows() > 0) {
83
+			$this->next_record();
84
+			return $this->Record;
85
+		} else {
86
+			return 0;
87
+		}
88
+	}
89 89
 
90
-    /**
91
-     * Db::lastInsertId()
92
-     * @param mixed $table
93
-     * @param mixed $field
94
-     * @return int
95
-     */
96
-    public function lastInsertId($table, $field)
97
-    {
98
-        return $this->getLastInsertId($table, $field);
99
-    }
90
+	/**
91
+	 * Db::lastInsertId()
92
+	 * @param mixed $table
93
+	 * @param mixed $field
94
+	 * @return int
95
+	 */
96
+	public function lastInsertId($table, $field)
97
+	{
98
+		return $this->getLastInsertId($table, $field);
99
+	}
100 100
 }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -18,8 +18,7 @@  discard block
 block discarded – undo
18 18
  *
19 19
  * @access public
20 20
  */
21
-class Db extends MysqliDb implements Db_Interface
22
-{
21
+class Db extends MysqliDb implements Db_Interface {
23 22
     public $host = 'localhost';
24 23
     public $user = 'pdns';
25 24
     public $password = '';
@@ -34,8 +33,7 @@  discard block
 block discarded – undo
34 33
      * @param string $type
35 34
      * @return string
36 35
      */
37
-    public function quote($text = '', $type = 'text')
38
-    {
36
+    public function quote($text = '', $type = 'text') {
39 37
         switch ($type) {
40 38
             case 'text':
41 39
                 return "'".$this->escape($text)."'";
@@ -57,8 +55,7 @@  discard block
 block discarded – undo
57 55
      * @param string $file
58 56
      * @return bool
59 57
      */
60
-    public function queryOne($query, $line = '', $file = '')
61
-    {
58
+    public function queryOne($query, $line = '', $file = '') {
62 59
         $this->query($query, $line, $file);
63 60
         if ($this->num_rows() > 0) {
64 61
             $this->next_record();
@@ -76,8 +73,7 @@  discard block
 block discarded – undo
76 73
      * @param string $file
77 74
      * @return array|bool
78 75
      */
79
-    public function queryRow($query, $line = '', $file = '')
80
-    {
76
+    public function queryRow($query, $line = '', $file = '') {
81 77
         $this->query($query, $line, $file);
82 78
         if ($this->num_rows() > 0) {
83 79
             $this->next_record();
@@ -93,8 +89,7 @@  discard block
 block discarded – undo
93 89
      * @param mixed $field
94 90
      * @return int
95 91
      */
96
-    public function lastInsertId($table, $field)
97
-    {
92
+    public function lastInsertId($table, $field) {
98 93
         return $this->getLastInsertId($table, $field);
99 94
     }
100 95
 }
Please login to merge, or discard this patch.
src/Db_Interface.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -16,57 +16,57 @@
 block discarded – undo
16 16
  */
17 17
 interface Db_Interface
18 18
 {
19
-    /**
20
-     * Db_Interface constructor.
21
-     *
22
-     * @param string $database
23
-     * @param string $user
24
-     * @param string $password
25
-     * @param string $host
26
-     * @param string $query
27
-     * @param string $port
28
-     */
29
-    public function __construct($database = '', $user = '', $password = '', $host = 'localhost', $query = '', $port = '');
19
+	/**
20
+	 * Db_Interface constructor.
21
+	 *
22
+	 * @param string $database
23
+	 * @param string $user
24
+	 * @param string $password
25
+	 * @param string $host
26
+	 * @param string $query
27
+	 * @param string $port
28
+	 */
29
+	public function __construct($database = '', $user = '', $password = '', $host = 'localhost', $query = '', $port = '');
30 30
 
31
-    /**
32
-     * @param $message
33
-     * @param string $line
34
-     * @param string $file
35
-     * @return mixed
36
-     */
37
-    public function log($message, $line = '', $file = '');
31
+	/**
32
+	 * @param $message
33
+	 * @param string $line
34
+	 * @param string $file
35
+	 * @return mixed
36
+	 */
37
+	public function log($message, $line = '', $file = '');
38 38
 
39
-    public function linkId();
39
+	public function linkId();
40 40
 
41
-    public function queryId();
41
+	public function queryId();
42 42
 
43
-    /**
44
-     * @param $str
45
-     * @return mixed
46
-     */
47
-    public function dbAddslashes($str);
43
+	/**
44
+	 * @param $str
45
+	 * @return mixed
46
+	 */
47
+	public function dbAddslashes($str);
48 48
 
49
-    /**
50
-     * @param $query
51
-     * @param string $line
52
-     * @param string $file
53
-     * @return mixed
54
-     */
55
-    public function qr($query, $line = '', $file = '');
49
+	/**
50
+	 * @param $query
51
+	 * @param string $line
52
+	 * @param string $file
53
+	 * @return mixed
54
+	 */
55
+	public function qr($query, $line = '', $file = '');
56 56
 
57
-    /**
58
-     * @param $msg
59
-     * @param string $line
60
-     * @param string $file
61
-     * @return mixed
62
-     */
63
-    public function halt($msg, $line = '', $file = '');
57
+	/**
58
+	 * @param $msg
59
+	 * @param string $line
60
+	 * @param string $file
61
+	 * @return mixed
62
+	 */
63
+	public function halt($msg, $line = '', $file = '');
64 64
 
65
-    /**
66
-     * @param $msg
67
-     * @return mixed
68
-     */
69
-    public function haltmsg($msg);
65
+	/**
66
+	 * @param $msg
67
+	 * @return mixed
68
+	 */
69
+	public function haltmsg($msg);
70 70
 
71
-    public function indexNames();
71
+	public function indexNames();
72 72
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,8 +14,7 @@
 block discarded – undo
14 14
  *
15 15
  * @package MyDb
16 16
  */
17
-interface Db_Interface
18
-{
17
+interface Db_Interface {
19 18
     /**
20 19
      * Db_Interface constructor.
21 20
      *
Please login to merge, or discard this patch.
src/Adodb/Db.php 2 patches
Indentation   +322 added lines, -322 removed lines patch added patch discarded remove patch
@@ -19,258 +19,258 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class Db extends Generic implements Db_Interface
21 21
 {
22
-    public $driver = 'mysql';
23
-    public $Rows = [];
24
-    public $type = 'adodb';
25
-
26
-    /**
27
-     * Db::connect()
28
-     * @param string $database
29
-     * @param string $host
30
-     * @param string $user
31
-     * @param string $password
32
-     * @param string $driver
33
-     * @return bool|\the
34
-     */
35
-    public function connect($database = '', $host = '', $user = '', $password = '', $driver = 'mysql')
36
-    {
37
-        /* Handle defaults */
38
-        if ('' == $database) {
39
-            $database = $this->database;
40
-        }
41
-        if ('' == $host) {
42
-            $host = $this->host;
43
-        }
44
-        if ('' == $user) {
45
-            $user = $this->user;
46
-        }
47
-        if ('' == $password) {
48
-            $password = $this->password;
49
-        }
50
-        if ('' == $driver) {
51
-            $driver = $this->driver;
52
-        }
53
-        /* establish connection, select database */
54
-        if ($this->linkId === false) {
55
-            $this->linkId = NewADOConnection($driver);
56
-            $this->linkId->Connect($host, $user, $password, $database);
57
-        }
58
-        return $this->linkId;
59
-    }
60
-
61
-    /* This only affects systems not using persistent connections */
62
-
63
-    /**
64
-     * Db::disconnect()
65
-     * @return void
66
-     */
67
-    public function disconnect()
68
-    {
69
-    }
70
-
71
-    /**
72
-     * @param $string
73
-     * @return string
74
-     */
75
-    public function real_escape($string = '')
76
-    {
77
-        return escapeshellarg($string);
78
-    }
79
-
80
-    /**
81
-     * discard the query result
82
-     * @return void
83
-     */
84
-    public function free()
85
-    {
86
-        //			@mysql_free_result($this->queryId);
87
-        //			$this->queryId = 0;
88
-    }
89
-
90
-    /**
91
-     * Db::queryReturn()
92
-     *
93
-     * Sends an SQL query to the server like the normal query() command but iterates through
94
-     * any rows and returns the row or rows immediately or FALSE on error
95
-     *
96
-     * @param mixed $query SQL Query to be used
97
-     * @param string $line optionally pass __LINE__ calling the query for logging
98
-     * @param string $file optionally pass __FILE__ calling the query for logging
99
-     * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
100
-     */
101
-    public function queryReturn($query, $line = '', $file = '')
102
-    {
103
-        $this->query($query, $line, $file);
104
-        if ($this->num_rows() == 0) {
105
-            return false;
106
-        } elseif ($this->num_rows() == 1) {
107
-            $this->next_record(MYSQL_ASSOC);
108
-            return $this->Record;
109
-        } else {
110
-            $out = [];
111
-            while ($this->next_record(MYSQL_ASSOC)) {
112
-                $out[] = $this->Record;
113
-            }
114
-            return $out;
115
-        }
116
-    }
117
-
118
-    /**
119
-     * db:qr()
120
-     *
121
-     *  alias of queryReturn()
122
-     *
123
-     * @param mixed $query SQL Query to be used
124
-     * @param string $line optionally pass __LINE__ calling the query for logging
125
-     * @param string $file optionally pass __FILE__ calling the query for logging
126
-     * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
127
-     */
128
-    public function qr($query, $line = '', $file = '')
129
-    {
130
-        return $this->queryReturn($query, $line, $file);
131
-    }
132
-
133
-    /**
134
-     * Db::query()
135
-     *
136
-     *  Sends an SQL query to the database
137
-     *
138
-     * @param mixed $queryString
139
-     * @param string $line
140
-     * @param string $file
141
-     * @return mixed 0 if no query or query id handler, safe to ignore this return
142
-     */
143
-    public function query($queryString, $line = '', $file = '')
144
-    {
145
-        /* No empty queries, please, since PHP4 chokes on them. */
146
-        /* The empty query string is passed on from the constructor,
22
+	public $driver = 'mysql';
23
+	public $Rows = [];
24
+	public $type = 'adodb';
25
+
26
+	/**
27
+	 * Db::connect()
28
+	 * @param string $database
29
+	 * @param string $host
30
+	 * @param string $user
31
+	 * @param string $password
32
+	 * @param string $driver
33
+	 * @return bool|\the
34
+	 */
35
+	public function connect($database = '', $host = '', $user = '', $password = '', $driver = 'mysql')
36
+	{
37
+		/* Handle defaults */
38
+		if ('' == $database) {
39
+			$database = $this->database;
40
+		}
41
+		if ('' == $host) {
42
+			$host = $this->host;
43
+		}
44
+		if ('' == $user) {
45
+			$user = $this->user;
46
+		}
47
+		if ('' == $password) {
48
+			$password = $this->password;
49
+		}
50
+		if ('' == $driver) {
51
+			$driver = $this->driver;
52
+		}
53
+		/* establish connection, select database */
54
+		if ($this->linkId === false) {
55
+			$this->linkId = NewADOConnection($driver);
56
+			$this->linkId->Connect($host, $user, $password, $database);
57
+		}
58
+		return $this->linkId;
59
+	}
60
+
61
+	/* This only affects systems not using persistent connections */
62
+
63
+	/**
64
+	 * Db::disconnect()
65
+	 * @return void
66
+	 */
67
+	public function disconnect()
68
+	{
69
+	}
70
+
71
+	/**
72
+	 * @param $string
73
+	 * @return string
74
+	 */
75
+	public function real_escape($string = '')
76
+	{
77
+		return escapeshellarg($string);
78
+	}
79
+
80
+	/**
81
+	 * discard the query result
82
+	 * @return void
83
+	 */
84
+	public function free()
85
+	{
86
+		//			@mysql_free_result($this->queryId);
87
+		//			$this->queryId = 0;
88
+	}
89
+
90
+	/**
91
+	 * Db::queryReturn()
92
+	 *
93
+	 * Sends an SQL query to the server like the normal query() command but iterates through
94
+	 * any rows and returns the row or rows immediately or FALSE on error
95
+	 *
96
+	 * @param mixed $query SQL Query to be used
97
+	 * @param string $line optionally pass __LINE__ calling the query for logging
98
+	 * @param string $file optionally pass __FILE__ calling the query for logging
99
+	 * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
100
+	 */
101
+	public function queryReturn($query, $line = '', $file = '')
102
+	{
103
+		$this->query($query, $line, $file);
104
+		if ($this->num_rows() == 0) {
105
+			return false;
106
+		} elseif ($this->num_rows() == 1) {
107
+			$this->next_record(MYSQL_ASSOC);
108
+			return $this->Record;
109
+		} else {
110
+			$out = [];
111
+			while ($this->next_record(MYSQL_ASSOC)) {
112
+				$out[] = $this->Record;
113
+			}
114
+			return $out;
115
+		}
116
+	}
117
+
118
+	/**
119
+	 * db:qr()
120
+	 *
121
+	 *  alias of queryReturn()
122
+	 *
123
+	 * @param mixed $query SQL Query to be used
124
+	 * @param string $line optionally pass __LINE__ calling the query for logging
125
+	 * @param string $file optionally pass __FILE__ calling the query for logging
126
+	 * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
127
+	 */
128
+	public function qr($query, $line = '', $file = '')
129
+	{
130
+		return $this->queryReturn($query, $line, $file);
131
+	}
132
+
133
+	/**
134
+	 * Db::query()
135
+	 *
136
+	 *  Sends an SQL query to the database
137
+	 *
138
+	 * @param mixed $queryString
139
+	 * @param string $line
140
+	 * @param string $file
141
+	 * @return mixed 0 if no query or query id handler, safe to ignore this return
142
+	 */
143
+	public function query($queryString, $line = '', $file = '')
144
+	{
145
+		/* No empty queries, please, since PHP4 chokes on them. */
146
+		/* The empty query string is passed on from the constructor,
147 147
         * when calling the class without a query, e.g. in situations
148 148
         * like these: '$db = new db_Subclass;'
149 149
         */
150
-        if ($queryString == '') {
151
-            return 0;
152
-        }
153
-        if (!$this->connect()) {
154
-            return 0;
155
-            /* we already complained in connect() about that. */
156
-        }
157
-
158
-        // New query, discard previous result.
159
-        if ($this->queryId !== false) {
160
-            $this->free();
161
-        }
162
-
163
-        if ($this->Debug) {
164
-            printf("Debug: query = %s<br>\n", $queryString);
165
-        }
166
-        if (isset($GLOBALS['log_queries']) && $GLOBALS['log_queries'] !== false) {
167
-            $this->log($queryString, $line, $file);
168
-        }
169
-
170
-        try {
171
-            $this->queryId = $this->linkId->Execute($queryString);
172
-        } catch (exception $e) {
173
-            $this->emailError($queryString, $e, $line, $file);
174
-        }
175
-        $this->log("ADOdb Query $queryString (S:$success) - ".count($this->Rows).' Rows', __LINE__, __FILE__);
176
-        $this->Row = 0;
177
-
178
-        // Will return nada if it fails. That's fine.
179
-        return $this->queryId;
180
-    }
181
-
182
-    /**
183
-     * Db::next_record()
184
-     * @param mixed $resultType
185
-     * @return bool
186
-     */
187
-    public function next_record($resultType = MYSQL_ASSOC)
188
-    {
189
-        if (!$this->queryId) {
190
-            $this->halt('next_record called with no query pending.');
191
-            return 0;
192
-        }
193
-        ++$this->Row;
194
-        $this->Record = $this->queryId->FetchRow();
195
-        $stat = is_array($this->Record);
196
-        if (!$stat && $this->autoFree) {
197
-            $this->free();
198
-        }
199
-        return $stat;
200
-    }
201
-
202
-    /* public: position in result set */
203
-
204
-    /**
205
-     * Db::seek()
206
-     * @param integer $pos
207
-     * @return int
208
-     */
209
-    public function seek($pos = 0)
210
-    {
211
-        if (isset($this->Rows[$pos])) {
212
-            $this->Row = $pos;
213
-        } else {
214
-            $this->halt("seek($pos) failed: result has ".count($this->Rows).' rows');
215
-            /* half assed attempt to save the day,
150
+		if ($queryString == '') {
151
+			return 0;
152
+		}
153
+		if (!$this->connect()) {
154
+			return 0;
155
+			/* we already complained in connect() about that. */
156
+		}
157
+
158
+		// New query, discard previous result.
159
+		if ($this->queryId !== false) {
160
+			$this->free();
161
+		}
162
+
163
+		if ($this->Debug) {
164
+			printf("Debug: query = %s<br>\n", $queryString);
165
+		}
166
+		if (isset($GLOBALS['log_queries']) && $GLOBALS['log_queries'] !== false) {
167
+			$this->log($queryString, $line, $file);
168
+		}
169
+
170
+		try {
171
+			$this->queryId = $this->linkId->Execute($queryString);
172
+		} catch (exception $e) {
173
+			$this->emailError($queryString, $e, $line, $file);
174
+		}
175
+		$this->log("ADOdb Query $queryString (S:$success) - ".count($this->Rows).' Rows', __LINE__, __FILE__);
176
+		$this->Row = 0;
177
+
178
+		// Will return nada if it fails. That's fine.
179
+		return $this->queryId;
180
+	}
181
+
182
+	/**
183
+	 * Db::next_record()
184
+	 * @param mixed $resultType
185
+	 * @return bool
186
+	 */
187
+	public function next_record($resultType = MYSQL_ASSOC)
188
+	{
189
+		if (!$this->queryId) {
190
+			$this->halt('next_record called with no query pending.');
191
+			return 0;
192
+		}
193
+		++$this->Row;
194
+		$this->Record = $this->queryId->FetchRow();
195
+		$stat = is_array($this->Record);
196
+		if (!$stat && $this->autoFree) {
197
+			$this->free();
198
+		}
199
+		return $stat;
200
+	}
201
+
202
+	/* public: position in result set */
203
+
204
+	/**
205
+	 * Db::seek()
206
+	 * @param integer $pos
207
+	 * @return int
208
+	 */
209
+	public function seek($pos = 0)
210
+	{
211
+		if (isset($this->Rows[$pos])) {
212
+			$this->Row = $pos;
213
+		} else {
214
+			$this->halt("seek($pos) failed: result has ".count($this->Rows).' rows');
215
+			/* half assed attempt to save the day,
216 216
             * but do not consider this documented or even
217 217
             * desirable behaviour.
218 218
             */
219
-            return 0;
220
-        }
221
-        return 1;
222
-    }
223
-
224
-    /**
225
-     * Db::transactionBegin()
226
-     * @return bool
227
-     */
228
-    public function transactionBegin()
229
-    {
230
-        return true;
231
-    }
232
-
233
-    /**
234
-     * Db::transactionCommit()
235
-     * @return bool
236
-     */
237
-    public function transactionCommit()
238
-    {
239
-        return true;
240
-    }
241
-
242
-    /**
243
-     * Db::transactionAbort()
244
-     * @return bool
245
-     */
246
-    public function transactionAbort()
247
-    {
248
-        return true;
249
-    }
250
-
251
-    /**
252
-     * Db::getLastInsertId()
253
-     *
254
-     * @param mixed $table
255
-     * @param mixed $field
256
-     * @return mixed
257
-     */
258
-    public function getLastInsertId($table, $field)
259
-    {
260
-        return $this->linkId->Insert_ID($table, $field);
261
-    }
262
-
263
-    /* public: table locking */
264
-
265
-    /**
266
-     * Db::lock()
267
-     * @param mixed  $table
268
-     * @param string $mode
269
-     * @return void
270
-     */
271
-    public function lock($table, $mode = 'write')
272
-    {
273
-        /*			$this->connect();
219
+			return 0;
220
+		}
221
+		return 1;
222
+	}
223
+
224
+	/**
225
+	 * Db::transactionBegin()
226
+	 * @return bool
227
+	 */
228
+	public function transactionBegin()
229
+	{
230
+		return true;
231
+	}
232
+
233
+	/**
234
+	 * Db::transactionCommit()
235
+	 * @return bool
236
+	 */
237
+	public function transactionCommit()
238
+	{
239
+		return true;
240
+	}
241
+
242
+	/**
243
+	 * Db::transactionAbort()
244
+	 * @return bool
245
+	 */
246
+	public function transactionAbort()
247
+	{
248
+		return true;
249
+	}
250
+
251
+	/**
252
+	 * Db::getLastInsertId()
253
+	 *
254
+	 * @param mixed $table
255
+	 * @param mixed $field
256
+	 * @return mixed
257
+	 */
258
+	public function getLastInsertId($table, $field)
259
+	{
260
+		return $this->linkId->Insert_ID($table, $field);
261
+	}
262
+
263
+	/* public: table locking */
264
+
265
+	/**
266
+	 * Db::lock()
267
+	 * @param mixed  $table
268
+	 * @param string $mode
269
+	 * @return void
270
+	 */
271
+	public function lock($table, $mode = 'write')
272
+	{
273
+		/*			$this->connect();
274 274
 
275 275
         * $query = "lock tables ";
276 276
         * if (is_array($table))
@@ -300,15 +300,15 @@  discard block
 block discarded – undo
300 300
         * }
301 301
         * return $res;
302 302
         */
303
-    }
303
+	}
304 304
 
305
-    /**
306
-     * Db::unlock()
307
-     * @return void
308
-     */
309
-    public function unlock()
310
-    {
311
-        /*			$this->connect();
305
+	/**
306
+	 * Db::unlock()
307
+	 * @return void
308
+	 */
309
+	public function unlock()
310
+	{
311
+		/*			$this->connect();
312 312
 
313 313
         * $res = @mysql_query("unlock tables");
314 314
         * if (!$res)
@@ -318,72 +318,72 @@  discard block
 block discarded – undo
318 318
         * }
319 319
         * return $res;
320 320
         */
321
-    }
322
-
323
-    /* public: evaluate the result (size, width) */
324
-
325
-    /**
326
-     * Db::affectedRows()
327
-     *
328
-     * @return mixed
329
-     */
330
-    public function affectedRows()
331
-    {
332
-        return @$this->linkId->Affected_Rows();
333
-        //			return @$this->queryId->rowCount();
334
-    }
335
-
336
-    /**
337
-     * Db::num_rows()
338
-     *
339
-     * @return mixed
340
-     */
341
-    public function num_rows()
342
-    {
343
-        return $this->queryId->NumRows();
344
-    }
345
-
346
-    /**
347
-     * Db::num_fields()
348
-     *
349
-     * @return mixed
350
-     */
351
-    public function num_fields()
352
-    {
353
-        return $this->queryId->NumCols();
354
-    }
355
-
356
-    /**
357
-     * @param mixed $msg
358
-     * @param string $line
359
-     * @param string $file
360
-     * @return mixed|void
361
-     */
362
-    public function haltmsg($msg, $line = '', $file = '')
363
-    {
364
-        $this->log("Database error: $msg", $line, $file, 'error');
365
-        if ($this->linkId->ErrorNo() != '0' && $this->linkId->ErrorMsg() != '') {
366
-            $this->log('ADOdb SQL Error: '.$this->linkId->ErrorMsg(), $line, $file, 'error');
367
-        }
368
-        $this->logBackTrace($msg, $line, $file);
369
-    }
370
-
371
-    /**
372
-     * Db::tableNames()
373
-     *
374
-     * @return array
375
-     */
376
-    public function tableNames()
377
-    {
378
-        $return = [];
379
-        $this->query('SHOW TABLES');
380
-        $i = 0;
381
-        while ($info = $this->queryId->FetchRow()) {
382
-            $return[$i]['table_name'] = $info[0];
383
-            $return[$i]['tablespace_name'] = $this->database;
384
-            $return[$i]['database'] = $this->database;
385
-            ++$i;
386
-        }
387
-        return $return;
388
-    }
321
+	}
322
+
323
+	/* public: evaluate the result (size, width) */
324
+
325
+	/**
326
+	 * Db::affectedRows()
327
+	 *
328
+	 * @return mixed
329
+	 */
330
+	public function affectedRows()
331
+	{
332
+		return @$this->linkId->Affected_Rows();
333
+		//			return @$this->queryId->rowCount();
334
+	}
335
+
336
+	/**
337
+	 * Db::num_rows()
338
+	 *
339
+	 * @return mixed
340
+	 */
341
+	public function num_rows()
342
+	{
343
+		return $this->queryId->NumRows();
344
+	}
345
+
346
+	/**
347
+	 * Db::num_fields()
348
+	 *
349
+	 * @return mixed
350
+	 */
351
+	public function num_fields()
352
+	{
353
+		return $this->queryId->NumCols();
354
+	}
355
+
356
+	/**
357
+	 * @param mixed $msg
358
+	 * @param string $line
359
+	 * @param string $file
360
+	 * @return mixed|void
361
+	 */
362
+	public function haltmsg($msg, $line = '', $file = '')
363
+	{
364
+		$this->log("Database error: $msg", $line, $file, 'error');
365
+		if ($this->linkId->ErrorNo() != '0' && $this->linkId->ErrorMsg() != '') {
366
+			$this->log('ADOdb SQL Error: '.$this->linkId->ErrorMsg(), $line, $file, 'error');
367
+		}
368
+		$this->logBackTrace($msg, $line, $file);
369
+	}
370
+
371
+	/**
372
+	 * Db::tableNames()
373
+	 *
374
+	 * @return array
375
+	 */
376
+	public function tableNames()
377
+	{
378
+		$return = [];
379
+		$this->query('SHOW TABLES');
380
+		$i = 0;
381
+		while ($info = $this->queryId->FetchRow()) {
382
+			$return[$i]['table_name'] = $info[0];
383
+			$return[$i]['tablespace_name'] = $this->database;
384
+			$return[$i]['database'] = $this->database;
385
+			++$i;
386
+		}
387
+		return $return;
388
+	}
389 389
 }
Please login to merge, or discard this patch.
Braces   +21 added lines, -42 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 $driver = 'mysql';
23 22
     public $Rows = [];
24 23
     public $type = 'adodb';
@@ -32,8 +31,7 @@  discard block
 block discarded – undo
32 31
      * @param string $driver
33 32
      * @return bool|\the
34 33
      */
35
-    public function connect($database = '', $host = '', $user = '', $password = '', $driver = 'mysql')
36
-    {
34
+    public function connect($database = '', $host = '', $user = '', $password = '', $driver = 'mysql') {
37 35
         /* Handle defaults */
38 36
         if ('' == $database) {
39 37
             $database = $this->database;
@@ -64,16 +62,14 @@  discard block
 block discarded – undo
64 62
      * Db::disconnect()
65 63
      * @return void
66 64
      */
67
-    public function disconnect()
68
-    {
65
+    public function disconnect() {
69 66
     }
70 67
 
71 68
     /**
72 69
      * @param $string
73 70
      * @return string
74 71
      */
75
-    public function real_escape($string = '')
76
-    {
72
+    public function real_escape($string = '') {
77 73
         return escapeshellarg($string);
78 74
     }
79 75
 
@@ -81,8 +77,7 @@  discard block
 block discarded – undo
81 77
      * discard the query result
82 78
      * @return void
83 79
      */
84
-    public function free()
85
-    {
80
+    public function free() {
86 81
         //			@mysql_free_result($this->queryId);
87 82
         //			$this->queryId = 0;
88 83
     }
@@ -98,8 +93,7 @@  discard block
 block discarded – undo
98 93
      * @param string $file optionally pass __FILE__ calling the query for logging
99 94
      * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
100 95
      */
101
-    public function queryReturn($query, $line = '', $file = '')
102
-    {
96
+    public function queryReturn($query, $line = '', $file = '') {
103 97
         $this->query($query, $line, $file);
104 98
         if ($this->num_rows() == 0) {
105 99
             return false;
@@ -125,8 +119,7 @@  discard block
 block discarded – undo
125 119
      * @param string $file optionally pass __FILE__ calling the query for logging
126 120
      * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
127 121
      */
128
-    public function qr($query, $line = '', $file = '')
129
-    {
122
+    public function qr($query, $line = '', $file = '') {
130 123
         return $this->queryReturn($query, $line, $file);
131 124
     }
132 125
 
@@ -140,8 +133,7 @@  discard block
 block discarded – undo
140 133
      * @param string $file
141 134
      * @return mixed 0 if no query or query id handler, safe to ignore this return
142 135
      */
143
-    public function query($queryString, $line = '', $file = '')
144
-    {
136
+    public function query($queryString, $line = '', $file = '') {
145 137
         /* No empty queries, please, since PHP4 chokes on them. */
146 138
         /* The empty query string is passed on from the constructor,
147 139
         * when calling the class without a query, e.g. in situations
@@ -184,8 +176,7 @@  discard block
 block discarded – undo
184 176
      * @param mixed $resultType
185 177
      * @return bool
186 178
      */
187
-    public function next_record($resultType = MYSQL_ASSOC)
188
-    {
179
+    public function next_record($resultType = MYSQL_ASSOC) {
189 180
         if (!$this->queryId) {
190 181
             $this->halt('next_record called with no query pending.');
191 182
             return 0;
@@ -206,8 +197,7 @@  discard block
 block discarded – undo
206 197
      * @param integer $pos
207 198
      * @return int
208 199
      */
209
-    public function seek($pos = 0)
210
-    {
200
+    public function seek($pos = 0) {
211 201
         if (isset($this->Rows[$pos])) {
212 202
             $this->Row = $pos;
213 203
         } else {
@@ -225,8 +215,7 @@  discard block
 block discarded – undo
225 215
      * Db::transactionBegin()
226 216
      * @return bool
227 217
      */
228
-    public function transactionBegin()
229
-    {
218
+    public function transactionBegin() {
230 219
         return true;
231 220
     }
232 221
 
@@ -234,8 +223,7 @@  discard block
 block discarded – undo
234 223
      * Db::transactionCommit()
235 224
      * @return bool
236 225
      */
237
-    public function transactionCommit()
238
-    {
226
+    public function transactionCommit() {
239 227
         return true;
240 228
     }
241 229
 
@@ -243,8 +231,7 @@  discard block
 block discarded – undo
243 231
      * Db::transactionAbort()
244 232
      * @return bool
245 233
      */
246
-    public function transactionAbort()
247
-    {
234
+    public function transactionAbort() {
248 235
         return true;
249 236
     }
250 237
 
@@ -255,8 +242,7 @@  discard block
 block discarded – undo
255 242
      * @param mixed $field
256 243
      * @return mixed
257 244
      */
258
-    public function getLastInsertId($table, $field)
259
-    {
245
+    public function getLastInsertId($table, $field) {
260 246
         return $this->linkId->Insert_ID($table, $field);
261 247
     }
262 248
 
@@ -268,8 +254,7 @@  discard block
 block discarded – undo
268 254
      * @param string $mode
269 255
      * @return void
270 256
      */
271
-    public function lock($table, $mode = 'write')
272
-    {
257
+    public function lock($table, $mode = 'write') {
273 258
         /*			$this->connect();
274 259
 
275 260
         * $query = "lock tables ";
@@ -306,8 +291,7 @@  discard block
 block discarded – undo
306 291
      * Db::unlock()
307 292
      * @return void
308 293
      */
309
-    public function unlock()
310
-    {
294
+    public function unlock() {
311 295
         /*			$this->connect();
312 296
 
313 297
         * $res = @mysql_query("unlock tables");
@@ -327,8 +311,7 @@  discard block
 block discarded – undo
327 311
      *
328 312
      * @return mixed
329 313
      */
330
-    public function affectedRows()
331
-    {
314
+    public function affectedRows() {
332 315
         return @$this->linkId->Affected_Rows();
333 316
         //			return @$this->queryId->rowCount();
334 317
     }
@@ -338,8 +321,7 @@  discard block
 block discarded – undo
338 321
      *
339 322
      * @return mixed
340 323
      */
341
-    public function num_rows()
342
-    {
324
+    public function num_rows() {
343 325
         return $this->queryId->NumRows();
344 326
     }
345 327
 
@@ -348,8 +330,7 @@  discard block
 block discarded – undo
348 330
      *
349 331
      * @return mixed
350 332
      */
351
-    public function num_fields()
352
-    {
333
+    public function num_fields() {
353 334
         return $this->queryId->NumCols();
354 335
     }
355 336
 
@@ -359,8 +340,7 @@  discard block
 block discarded – undo
359 340
      * @param string $file
360 341
      * @return mixed|void
361 342
      */
362
-    public function haltmsg($msg, $line = '', $file = '')
363
-    {
343
+    public function haltmsg($msg, $line = '', $file = '') {
364 344
         $this->log("Database error: $msg", $line, $file, 'error');
365 345
         if ($this->linkId->ErrorNo() != '0' && $this->linkId->ErrorMsg() != '') {
366 346
             $this->log('ADOdb SQL Error: '.$this->linkId->ErrorMsg(), $line, $file, 'error');
@@ -373,8 +353,7 @@  discard block
 block discarded – undo
373 353
      *
374 354
      * @return array
375 355
      */
376
-    public function tableNames()
377
-    {
356
+    public function tableNames() {
378 357
         $return = [];
379 358
         $this->query('SHOW TABLES');
380 359
         $i = 0;
Please login to merge, or discard this patch.
src/Pdo/Db.php 2 patches
Indentation   +316 added lines, -316 removed lines patch added patch discarded remove patch
@@ -20,256 +20,256 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class Db extends Generic implements Db_Interface
22 22
 {
23
-    /* public: connection parameters */
24
-    public $driver = 'mysql';
25
-    public $Rows = [];
26
-    /* public: this is an api revision, not a CVS revision. */
27
-    public $type = 'pdo';
28
-
29
-    /**
30
-     * changes the database we are working with.
31
-     *
32
-     * @param string $database the name of the database to use
33
-     * @return void
34
-     */
35
-    public function selectDb($database)
36
-    {
37
-        $dSN = "{$this->driver}:dbname={$database};host={$this->host}";
38
-        if ($this->characterSet != '') {
39
-            $dSN .= ';charset='.$this->characterSet;
40
-        }
41
-        $this->linkId = new PDO($dSN, $this->user, $this->password);
42
-        $this->database = $database;
43
-    }
44
-
45
-
46
-    /**
47
-     * alias function of select_db, changes the database we are working with.
48
-     *
49
-     * @param string $database the name of the database to use
50
-     * @return void
51
-     */
52
-    public function useDb($database)
53
-    {
54
-        $this->selectDb($database);
55
-    }
56
-
57
-    /* public: connection management */
58
-
59
-    /**
60
-     * Db::connect()
61
-     * @param string $database
62
-     * @param string $host
63
-     * @param string $user
64
-     * @param string $password
65
-     * @param string $driver
66
-     * @return bool|int|PDO
67
-     */
68
-    public function connect($database = '', $host = '', $user = '', $password = '', $driver = 'mysql')
69
-    {
70
-        /* Handle defaults */
71
-        if ('' == $database) {
72
-            $database = $this->database;
73
-        }
74
-        if ('' == $host) {
75
-            $host = $this->host;
76
-        }
77
-        if ('' == $user) {
78
-            $user = $this->user;
79
-        }
80
-        if ('' == $password) {
81
-            $password = $this->password;
82
-        }
83
-        if ('' == $driver) {
84
-            $driver = $this->driver;
85
-        }
86
-        /* establish connection, select database */
87
-        $dSN = "{$driver}:dbname={$database};host={$host}";
88
-        if ($this->characterSet != '') {
89
-            $dSN .= ';charset='.$this->characterSet;
90
-        }
91
-        if ($this->linkId === false) {
92
-            try {
93
-                $this->linkId = new PDO($dSN, $user, $password);
94
-            } catch (\PDOException $e) {
95
-                $this->halt('Connection Failed '.$e->getMessage());
96
-                return 0;
97
-            }
98
-        }
99
-        return $this->linkId;
100
-    }
101
-
102
-    /* This only affects systems not using persistent connections */
103
-
104
-    /**
105
-     * Db::disconnect()
106
-     * @return void
107
-     */
108
-    public function disconnect()
109
-    {
110
-    }
111
-
112
-    /* public: discard the query result */
113
-
114
-    /**
115
-     * Db::free()
116
-     * @return void
117
-     */
118
-    public function free()
119
-    {
120
-        //			@mysql_free_result($this->queryId);
121
-        //			$this->queryId = 0;
122
-    }
123
-
124
-    /**
125
-     * Db::query()
126
-     *
127
-     *  Sends an SQL query to the database
128
-     *
129
-     * @param mixed $queryString
130
-     * @param string $line
131
-     * @param string $file
132
-     * @return mixed 0 if no query or query id handler, safe to ignore this return
133
-     */
134
-    public function query($queryString, $line = '', $file = '')
135
-    {
136
-        /* No empty queries, please, since PHP4 chokes on them. */
137
-        /* The empty query string is passed on from the constructor,
23
+	/* public: connection parameters */
24
+	public $driver = 'mysql';
25
+	public $Rows = [];
26
+	/* public: this is an api revision, not a CVS revision. */
27
+	public $type = 'pdo';
28
+
29
+	/**
30
+	 * changes the database we are working with.
31
+	 *
32
+	 * @param string $database the name of the database to use
33
+	 * @return void
34
+	 */
35
+	public function selectDb($database)
36
+	{
37
+		$dSN = "{$this->driver}:dbname={$database};host={$this->host}";
38
+		if ($this->characterSet != '') {
39
+			$dSN .= ';charset='.$this->characterSet;
40
+		}
41
+		$this->linkId = new PDO($dSN, $this->user, $this->password);
42
+		$this->database = $database;
43
+	}
44
+
45
+
46
+	/**
47
+	 * alias function of select_db, changes the database we are working with.
48
+	 *
49
+	 * @param string $database the name of the database to use
50
+	 * @return void
51
+	 */
52
+	public function useDb($database)
53
+	{
54
+		$this->selectDb($database);
55
+	}
56
+
57
+	/* public: connection management */
58
+
59
+	/**
60
+	 * Db::connect()
61
+	 * @param string $database
62
+	 * @param string $host
63
+	 * @param string $user
64
+	 * @param string $password
65
+	 * @param string $driver
66
+	 * @return bool|int|PDO
67
+	 */
68
+	public function connect($database = '', $host = '', $user = '', $password = '', $driver = 'mysql')
69
+	{
70
+		/* Handle defaults */
71
+		if ('' == $database) {
72
+			$database = $this->database;
73
+		}
74
+		if ('' == $host) {
75
+			$host = $this->host;
76
+		}
77
+		if ('' == $user) {
78
+			$user = $this->user;
79
+		}
80
+		if ('' == $password) {
81
+			$password = $this->password;
82
+		}
83
+		if ('' == $driver) {
84
+			$driver = $this->driver;
85
+		}
86
+		/* establish connection, select database */
87
+		$dSN = "{$driver}:dbname={$database};host={$host}";
88
+		if ($this->characterSet != '') {
89
+			$dSN .= ';charset='.$this->characterSet;
90
+		}
91
+		if ($this->linkId === false) {
92
+			try {
93
+				$this->linkId = new PDO($dSN, $user, $password);
94
+			} catch (\PDOException $e) {
95
+				$this->halt('Connection Failed '.$e->getMessage());
96
+				return 0;
97
+			}
98
+		}
99
+		return $this->linkId;
100
+	}
101
+
102
+	/* This only affects systems not using persistent connections */
103
+
104
+	/**
105
+	 * Db::disconnect()
106
+	 * @return void
107
+	 */
108
+	public function disconnect()
109
+	{
110
+	}
111
+
112
+	/* public: discard the query result */
113
+
114
+	/**
115
+	 * Db::free()
116
+	 * @return void
117
+	 */
118
+	public function free()
119
+	{
120
+		//			@mysql_free_result($this->queryId);
121
+		//			$this->queryId = 0;
122
+	}
123
+
124
+	/**
125
+	 * Db::query()
126
+	 *
127
+	 *  Sends an SQL query to the database
128
+	 *
129
+	 * @param mixed $queryString
130
+	 * @param string $line
131
+	 * @param string $file
132
+	 * @return mixed 0 if no query or query id handler, safe to ignore this return
133
+	 */
134
+	public function query($queryString, $line = '', $file = '')
135
+	{
136
+		/* No empty queries, please, since PHP4 chokes on them. */
137
+		/* The empty query string is passed on from the constructor,
138 138
         * when calling the class without a query, e.g. in situations
139 139
         * like these: '$db = new db_Subclass;'
140 140
         */
141
-        if ($queryString == '') {
142
-            return 0;
143
-        }
144
-        if (!$this->connect()) {
145
-            return 0;
146
-            /* we already complained in connect() about that. */
147
-        }
148
-        // New query, discard previous result.
149
-        if ($this->queryId !== false) {
150
-            $this->free();
151
-        }
152
-
153
-        if ($this->Debug) {
154
-            printf("Debug: query = %s<br>\n", $queryString);
155
-        }
156
-        if (isset($GLOBALS['log_queries']) && $GLOBALS['log_queries'] !== false) {
157
-            $this->log($queryString, $line, $file);
158
-        }
159
-
160
-        $this->queryId = $this->linkId->prepare($queryString);
161
-        $success = $this->queryId->execute();
162
-        $this->Rows = $this->queryId->fetchAll();
163
-        //$this->log("PDO Query $queryString (S:$success) - ".count($this->Rows).' Rows', __LINE__, __FILE__);
164
-        $this->Row = -1;
165
-        if ($success === false) {
166
-            $this->emailError($queryString, json_encode($this->queryId->errorInfo(), JSON_PRETTY_PRINT), $line, $file);
167
-        }
168
-
169
-        // Will return nada if it fails. That's fine.
170
-        return $this->queryId;
171
-    }
172
-
173
-    /* public: walk result set */
174
-
175
-    /**
176
-     * Db::next_record()
177
-     * @param mixed $resultType
178
-     * @return bool
179
-     */
180
-    public function next_record($resultType = MYSQLI_ASSOC)
181
-    {
182
-        // PDO result types so far seem to be +1
183
-        ++$resultType;
184
-        if (!$this->queryId) {
185
-            $this->halt('next_record called with no query pending.');
186
-            return 0;
187
-        }
188
-
189
-        ++$this->Row;
190
-        $this->Record = $this->Rows[$this->Row];
191
-
192
-        $stat = is_array($this->Record);
193
-        if (!$stat && $this->autoFree) {
194
-            $this->free();
195
-        }
196
-        return $stat;
197
-    }
198
-
199
-    /* public: position in result set */
200
-
201
-    /**
202
-     * Db::seek()
203
-     * @param integer $pos
204
-     * @return int
205
-     */
206
-    public function seek($pos = 0)
207
-    {
208
-        if (isset($this->Rows[$pos])) {
209
-            $this->Row = $pos;
210
-        } else {
211
-            $this->halt("seek($pos) failed: result has ".count($this->Rows).' rows');
212
-            /* half assed attempt to save the day,
141
+		if ($queryString == '') {
142
+			return 0;
143
+		}
144
+		if (!$this->connect()) {
145
+			return 0;
146
+			/* we already complained in connect() about that. */
147
+		}
148
+		// New query, discard previous result.
149
+		if ($this->queryId !== false) {
150
+			$this->free();
151
+		}
152
+
153
+		if ($this->Debug) {
154
+			printf("Debug: query = %s<br>\n", $queryString);
155
+		}
156
+		if (isset($GLOBALS['log_queries']) && $GLOBALS['log_queries'] !== false) {
157
+			$this->log($queryString, $line, $file);
158
+		}
159
+
160
+		$this->queryId = $this->linkId->prepare($queryString);
161
+		$success = $this->queryId->execute();
162
+		$this->Rows = $this->queryId->fetchAll();
163
+		//$this->log("PDO Query $queryString (S:$success) - ".count($this->Rows).' Rows', __LINE__, __FILE__);
164
+		$this->Row = -1;
165
+		if ($success === false) {
166
+			$this->emailError($queryString, json_encode($this->queryId->errorInfo(), JSON_PRETTY_PRINT), $line, $file);
167
+		}
168
+
169
+		// Will return nada if it fails. That's fine.
170
+		return $this->queryId;
171
+	}
172
+
173
+	/* public: walk result set */
174
+
175
+	/**
176
+	 * Db::next_record()
177
+	 * @param mixed $resultType
178
+	 * @return bool
179
+	 */
180
+	public function next_record($resultType = MYSQLI_ASSOC)
181
+	{
182
+		// PDO result types so far seem to be +1
183
+		++$resultType;
184
+		if (!$this->queryId) {
185
+			$this->halt('next_record called with no query pending.');
186
+			return 0;
187
+		}
188
+
189
+		++$this->Row;
190
+		$this->Record = $this->Rows[$this->Row];
191
+
192
+		$stat = is_array($this->Record);
193
+		if (!$stat && $this->autoFree) {
194
+			$this->free();
195
+		}
196
+		return $stat;
197
+	}
198
+
199
+	/* public: position in result set */
200
+
201
+	/**
202
+	 * Db::seek()
203
+	 * @param integer $pos
204
+	 * @return int
205
+	 */
206
+	public function seek($pos = 0)
207
+	{
208
+		if (isset($this->Rows[$pos])) {
209
+			$this->Row = $pos;
210
+		} else {
211
+			$this->halt("seek($pos) failed: result has ".count($this->Rows).' rows');
212
+			/* half assed attempt to save the day,
213 213
             * but do not consider this documented or even
214 214
             * desirable behaviour.
215 215
             */
216
-            return 0;
217
-        }
218
-        return 1;
219
-    }
220
-
221
-    /**
222
-     * Initiates a transaction
223
-     * @return bool
224
-     */
225
-    public function transactionBegin()
226
-    {
227
-        return $this->linkId->beginTransaction();
228
-    }
229
-
230
-    /**
231
-     * Commits a transaction
232
-     * @return bool
233
-     */
234
-    public function transactionCommit()
235
-    {
236
-        return $this->linkId->commit();
237
-    }
238
-
239
-    /**
240
-     * Rolls back a transaction
241
-     * @return bool
242
-     */
243
-    public function transactionAbort()
244
-    {
245
-        return $this->linkId->rollBack();
246
-    }
247
-
248
-    /**
249
-     * Db::getLastInsertId()
250
-     * @param mixed $table
251
-     * @param mixed $field
252
-     * @return int
253
-     */
254
-    public function getLastInsertId($table, $field)
255
-    {
256
-        if (!isset($table) || $table == '' || !isset($field) || $field == '') {
257
-            return -1;
258
-        }
259
-        return $this->linkId->lastInsertId();
260
-    }
261
-
262
-    /* public: table locking */
263
-
264
-    /**
265
-     * Db::lock()
266
-     * @param mixed  $table
267
-     * @param string $mode
268
-     * @return void
269
-     */
270
-    public function lock($table, $mode = 'write')
271
-    {
272
-        /*			$this->connect();
216
+			return 0;
217
+		}
218
+		return 1;
219
+	}
220
+
221
+	/**
222
+	 * Initiates a transaction
223
+	 * @return bool
224
+	 */
225
+	public function transactionBegin()
226
+	{
227
+		return $this->linkId->beginTransaction();
228
+	}
229
+
230
+	/**
231
+	 * Commits a transaction
232
+	 * @return bool
233
+	 */
234
+	public function transactionCommit()
235
+	{
236
+		return $this->linkId->commit();
237
+	}
238
+
239
+	/**
240
+	 * Rolls back a transaction
241
+	 * @return bool
242
+	 */
243
+	public function transactionAbort()
244
+	{
245
+		return $this->linkId->rollBack();
246
+	}
247
+
248
+	/**
249
+	 * Db::getLastInsertId()
250
+	 * @param mixed $table
251
+	 * @param mixed $field
252
+	 * @return int
253
+	 */
254
+	public function getLastInsertId($table, $field)
255
+	{
256
+		if (!isset($table) || $table == '' || !isset($field) || $field == '') {
257
+			return -1;
258
+		}
259
+		return $this->linkId->lastInsertId();
260
+	}
261
+
262
+	/* public: table locking */
263
+
264
+	/**
265
+	 * Db::lock()
266
+	 * @param mixed  $table
267
+	 * @param string $mode
268
+	 * @return void
269
+	 */
270
+	public function lock($table, $mode = 'write')
271
+	{
272
+		/*			$this->connect();
273 273
 
274 274
         * $query = "lock tables ";
275 275
         * if (is_array($table))
@@ -299,15 +299,15 @@  discard block
 block discarded – undo
299 299
         * }
300 300
         * return $res;
301 301
         */
302
-    }
302
+	}
303 303
 
304
-    /**
305
-     * Db::unlock()
306
-     * @return void
307
-     */
308
-    public function unlock()
309
-    {
310
-        /*			$this->connect();
304
+	/**
305
+	 * Db::unlock()
306
+	 * @return void
307
+	 */
308
+	public function unlock()
309
+	{
310
+		/*			$this->connect();
311 311
 
312 312
         * $res = @mysql_query("unlock tables");
313 313
         * if (!$res)
@@ -317,68 +317,68 @@  discard block
 block discarded – undo
317 317
         * }
318 318
         * return $res;
319 319
         */
320
-    }
321
-
322
-    /* public: evaluate the result (size, width) */
323
-
324
-    /**
325
-     * Db::affectedRows()
326
-     *
327
-     * @return mixed
328
-     */
329
-    public function affectedRows()
330
-    {
331
-        return @$this->queryId->rowCount();
332
-    }
333
-
334
-    /**
335
-     * Db::num_rows()
336
-     * @return int
337
-     */
338
-    public function num_rows()
339
-    {
340
-        return count($this->Rows);
341
-    }
342
-
343
-    /**
344
-     * Db::num_fields()
345
-     * @return int
346
-     */
347
-    public function num_fields()
348
-    {
349
-        $keys = array_keys($this->Rows);
350
-        return count($this->Rows[$keys[0]]);
351
-    }
352
-
353
-    /**
354
-     * @param mixed $msg
355
-     * @param string $line
356
-     * @param string $file
357
-     * @return mixed|void
358
-     */
359
-    public function haltmsg($msg, $line = '', $file = '')
360
-    {
361
-        $this->log("Database error: $msg", $line, $file, 'error');
362
-        if ($this->Errno != '0' || $this->Error != '()') {
363
-            $this->log('PDO MySQL Error: '.json_encode($this->linkId->errorInfo()), $line, $file, 'error');
364
-        }
365
-        $this->logBackTrace($msg, $line, $file);
366
-    }
367
-
368
-    /**
369
-     * Db::tableNames()
370
-     *
371
-     * @return array
372
-     */
373
-    public function tableNames()
374
-    {
375
-        $return = [];
376
-        $this->query('SHOW TABLES');
377
-        foreach ($this->Rows as $i => $info) {
378
-            $return[$i]['table_name'] = $info[0];
379
-            $return[$i]['tablespace_name'] = $this->database;
380
-            $return[$i]['database'] = $this->database;
381
-        }
382
-        return $return;
383
-    }
320
+	}
321
+
322
+	/* public: evaluate the result (size, width) */
323
+
324
+	/**
325
+	 * Db::affectedRows()
326
+	 *
327
+	 * @return mixed
328
+	 */
329
+	public function affectedRows()
330
+	{
331
+		return @$this->queryId->rowCount();
332
+	}
333
+
334
+	/**
335
+	 * Db::num_rows()
336
+	 * @return int
337
+	 */
338
+	public function num_rows()
339
+	{
340
+		return count($this->Rows);
341
+	}
342
+
343
+	/**
344
+	 * Db::num_fields()
345
+	 * @return int
346
+	 */
347
+	public function num_fields()
348
+	{
349
+		$keys = array_keys($this->Rows);
350
+		return count($this->Rows[$keys[0]]);
351
+	}
352
+
353
+	/**
354
+	 * @param mixed $msg
355
+	 * @param string $line
356
+	 * @param string $file
357
+	 * @return mixed|void
358
+	 */
359
+	public function haltmsg($msg, $line = '', $file = '')
360
+	{
361
+		$this->log("Database error: $msg", $line, $file, 'error');
362
+		if ($this->Errno != '0' || $this->Error != '()') {
363
+			$this->log('PDO MySQL Error: '.json_encode($this->linkId->errorInfo()), $line, $file, 'error');
364
+		}
365
+		$this->logBackTrace($msg, $line, $file);
366
+	}
367
+
368
+	/**
369
+	 * Db::tableNames()
370
+	 *
371
+	 * @return array
372
+	 */
373
+	public function tableNames()
374
+	{
375
+		$return = [];
376
+		$this->query('SHOW TABLES');
377
+		foreach ($this->Rows as $i => $info) {
378
+			$return[$i]['table_name'] = $info[0];
379
+			$return[$i]['tablespace_name'] = $this->database;
380
+			$return[$i]['database'] = $this->database;
381
+		}
382
+		return $return;
383
+	}
384 384
 }
Please login to merge, or discard this patch.
Braces   +20 added lines, -40 removed lines patch added patch discarded remove patch
@@ -18,8 +18,7 @@  discard block
 block discarded – undo
18 18
  *
19 19
  * @access public
20 20
  */
21
-class Db extends Generic implements Db_Interface
22
-{
21
+class Db extends Generic implements Db_Interface {
23 22
     /* public: connection parameters */
24 23
     public $driver = 'mysql';
25 24
     public $Rows = [];
@@ -32,8 +31,7 @@  discard block
 block discarded – undo
32 31
      * @param string $database the name of the database to use
33 32
      * @return void
34 33
      */
35
-    public function selectDb($database)
36
-    {
34
+    public function selectDb($database) {
37 35
         $dSN = "{$this->driver}:dbname={$database};host={$this->host}";
38 36
         if ($this->characterSet != '') {
39 37
             $dSN .= ';charset='.$this->characterSet;
@@ -49,8 +47,7 @@  discard block
 block discarded – undo
49 47
      * @param string $database the name of the database to use
50 48
      * @return void
51 49
      */
52
-    public function useDb($database)
53
-    {
50
+    public function useDb($database) {
54 51
         $this->selectDb($database);
55 52
     }
56 53
 
@@ -65,8 +62,7 @@  discard block
 block discarded – undo
65 62
      * @param string $driver
66 63
      * @return bool|int|PDO
67 64
      */
68
-    public function connect($database = '', $host = '', $user = '', $password = '', $driver = 'mysql')
69
-    {
65
+    public function connect($database = '', $host = '', $user = '', $password = '', $driver = 'mysql') {
70 66
         /* Handle defaults */
71 67
         if ('' == $database) {
72 68
             $database = $this->database;
@@ -105,8 +101,7 @@  discard block
 block discarded – undo
105 101
      * Db::disconnect()
106 102
      * @return void
107 103
      */
108
-    public function disconnect()
109
-    {
104
+    public function disconnect() {
110 105
     }
111 106
 
112 107
     /* public: discard the query result */
@@ -115,8 +110,7 @@  discard block
 block discarded – undo
115 110
      * Db::free()
116 111
      * @return void
117 112
      */
118
-    public function free()
119
-    {
113
+    public function free() {
120 114
         //			@mysql_free_result($this->queryId);
121 115
         //			$this->queryId = 0;
122 116
     }
@@ -131,8 +125,7 @@  discard block
 block discarded – undo
131 125
      * @param string $file
132 126
      * @return mixed 0 if no query or query id handler, safe to ignore this return
133 127
      */
134
-    public function query($queryString, $line = '', $file = '')
135
-    {
128
+    public function query($queryString, $line = '', $file = '') {
136 129
         /* No empty queries, please, since PHP4 chokes on them. */
137 130
         /* The empty query string is passed on from the constructor,
138 131
         * when calling the class without a query, e.g. in situations
@@ -177,8 +170,7 @@  discard block
 block discarded – undo
177 170
      * @param mixed $resultType
178 171
      * @return bool
179 172
      */
180
-    public function next_record($resultType = MYSQLI_ASSOC)
181
-    {
173
+    public function next_record($resultType = MYSQLI_ASSOC) {
182 174
         // PDO result types so far seem to be +1
183 175
         ++$resultType;
184 176
         if (!$this->queryId) {
@@ -203,8 +195,7 @@  discard block
 block discarded – undo
203 195
      * @param integer $pos
204 196
      * @return int
205 197
      */
206
-    public function seek($pos = 0)
207
-    {
198
+    public function seek($pos = 0) {
208 199
         if (isset($this->Rows[$pos])) {
209 200
             $this->Row = $pos;
210 201
         } else {
@@ -222,8 +213,7 @@  discard block
 block discarded – undo
222 213
      * Initiates a transaction
223 214
      * @return bool
224 215
      */
225
-    public function transactionBegin()
226
-    {
216
+    public function transactionBegin() {
227 217
         return $this->linkId->beginTransaction();
228 218
     }
229 219
 
@@ -231,8 +221,7 @@  discard block
 block discarded – undo
231 221
      * Commits a transaction
232 222
      * @return bool
233 223
      */
234
-    public function transactionCommit()
235
-    {
224
+    public function transactionCommit() {
236 225
         return $this->linkId->commit();
237 226
     }
238 227
 
@@ -240,8 +229,7 @@  discard block
 block discarded – undo
240 229
      * Rolls back a transaction
241 230
      * @return bool
242 231
      */
243
-    public function transactionAbort()
244
-    {
232
+    public function transactionAbort() {
245 233
         return $this->linkId->rollBack();
246 234
     }
247 235
 
@@ -251,8 +239,7 @@  discard block
 block discarded – undo
251 239
      * @param mixed $field
252 240
      * @return int
253 241
      */
254
-    public function getLastInsertId($table, $field)
255
-    {
242
+    public function getLastInsertId($table, $field) {
256 243
         if (!isset($table) || $table == '' || !isset($field) || $field == '') {
257 244
             return -1;
258 245
         }
@@ -267,8 +254,7 @@  discard block
 block discarded – undo
267 254
      * @param string $mode
268 255
      * @return void
269 256
      */
270
-    public function lock($table, $mode = 'write')
271
-    {
257
+    public function lock($table, $mode = 'write') {
272 258
         /*			$this->connect();
273 259
 
274 260
         * $query = "lock tables ";
@@ -305,8 +291,7 @@  discard block
 block discarded – undo
305 291
      * Db::unlock()
306 292
      * @return void
307 293
      */
308
-    public function unlock()
309
-    {
294
+    public function unlock() {
310 295
         /*			$this->connect();
311 296
 
312 297
         * $res = @mysql_query("unlock tables");
@@ -326,8 +311,7 @@  discard block
 block discarded – undo
326 311
      *
327 312
      * @return mixed
328 313
      */
329
-    public function affectedRows()
330
-    {
314
+    public function affectedRows() {
331 315
         return @$this->queryId->rowCount();
332 316
     }
333 317
 
@@ -335,8 +319,7 @@  discard block
 block discarded – undo
335 319
      * Db::num_rows()
336 320
      * @return int
337 321
      */
338
-    public function num_rows()
339
-    {
322
+    public function num_rows() {
340 323
         return count($this->Rows);
341 324
     }
342 325
 
@@ -344,8 +327,7 @@  discard block
 block discarded – undo
344 327
      * Db::num_fields()
345 328
      * @return int
346 329
      */
347
-    public function num_fields()
348
-    {
330
+    public function num_fields() {
349 331
         $keys = array_keys($this->Rows);
350 332
         return count($this->Rows[$keys[0]]);
351 333
     }
@@ -356,8 +338,7 @@  discard block
 block discarded – undo
356 338
      * @param string $file
357 339
      * @return mixed|void
358 340
      */
359
-    public function haltmsg($msg, $line = '', $file = '')
360
-    {
341
+    public function haltmsg($msg, $line = '', $file = '') {
361 342
         $this->log("Database error: $msg", $line, $file, 'error');
362 343
         if ($this->Errno != '0' || $this->Error != '()') {
363 344
             $this->log('PDO MySQL Error: '.json_encode($this->linkId->errorInfo()), $line, $file, 'error');
@@ -370,8 +351,7 @@  discard block
 block discarded – undo
370 351
      *
371 352
      * @return array
372 353
      */
373
-    public function tableNames()
374
-    {
354
+    public function tableNames() {
375 355
         $return = [];
376 356
         $this->query('SHOW TABLES');
377 357
         foreach ($this->Rows as $i => $info) {
Please login to merge, or discard this patch.
src/Generic.php 2 patches
Indentation   +383 added lines, -383 removed lines patch added patch discarded remove patch
@@ -14,387 +14,387 @@
 block discarded – undo
14 14
  */
15 15
 abstract class Generic
16 16
 {
17
-    /* public: connection parameters */
18
-    public $host = 'localhost';
19
-    public $database = '';
20
-    public $user = '';
21
-    public $password = '';
22
-    public $port = '';
23
-
24
-    /* public: configuration parameters */
25
-    public $autoStripslashes = false;
26
-    public $Debug = 0; // Set to 1 for debugging messages.
27
-    public $haltOnError = 'yes'; // "yes" (halt with message), "no" (ignore errors quietly), "report" (ignore error, but spit a warning)
28
-
29
-    public $maxConnectErrors = 5;
30
-    public $connectionAttempt = 0;
31
-    public $maxMatches = 10000000;
32
-
33
-    public $Type = 'mysql';
34
-
35
-    /**
36
-     * @var int
37
-     */
38
-    public $autoFree = 0; // Set to 1 for automatic mysql_free_result()
39
-
40
-    /* public: result array and current row number */
41
-    public $Record = [];
42
-    public $Row;
43
-
44
-    /* public: current error number and error text */
45
-    public $Errno = 0;
46
-    public $Error = '';
47
-
48
-    /* public: this is an api revision, not a CVS revision. */
49
-    public $type = 'generic';
50
-
51
-    /**
52
-     * @var int|object
53
-     */
54
-    public $linkId = 0;
55
-    public $queryId = 0;
56
-
57
-    public $characterSet = 'utf8mb4';
58
-    public $collation = 'utf8mb4_unicode_ci';
59
-
60
-    /**
61
-     * Logged queries.
62
-     * @var array
63
-     */
64
-    protected $log = [];
65
-
66
-    /**
67
-     * Constructs the db handler, can optionally specify connection parameters
68
-     *
69
-     * @param string $database Optional The database name
70
-     * @param string $user Optional The username to connect with
71
-     * @param string $password Optional The password to use
72
-     * @param string $host Optional The hostname where the server is, or default to localhost
73
-     * @param string $query Optional query to perform immediately
74
-     * @param string $port optional port for the connection
75
-     */
76
-    public function __construct($database = '', $user = '', $password = '', $host = 'localhost', $query = '', $port = '')
77
-    {
78
-        $this->database = $database;
79
-        $this->user = $user;
80
-        $this->password = $password;
81
-        $this->host = $host;
82
-        $this->port = $port;
83
-        if ($query != '') {
84
-            $this->query($query);
85
-        }
86
-        $this->connectionAttempt = 0;
87
-    }
88
-
89
-    /**
90
-     * @param string $message
91
-     * @param string $line
92
-     * @param string $file
93
-     * @return void
94
-     */
95
-    public function log($message, $line = '', $file = '', $level = 'info')
96
-    {
97
-        error_log('SQL Query '.$line.' '.$file.' '.$message);
98
-    }
99
-
100
-    /**
101
-     * @return int|object
102
-     */
103
-    public function linkId()
104
-    {
105
-        return $this->linkId;
106
-    }
107
-
108
-    /**
109
-     * @return int|object
110
-     */
111
-    public function queryId()
112
-    {
113
-        return $this->queryId;
114
-    }
115
-
116
-    /**
117
-     * @param $string
118
-     * @return string
119
-     */
120
-    public function real_escape($string = '')
121
-    {
122
-        if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect()) {
123
-            return $this->escape($string);
124
-        }
125
-        return mysqli_real_escape_string($this->linkId, $string);
126
-    }
127
-
128
-    /**
129
-     * @param $string
130
-     * @return string
131
-     */
132
-    public function escape($string = '')
133
-    {
134
-        //if (function_exists('mysql_escape_string'))
135
-        //return mysql_escape_string($string);
136
-        return str_replace(['\\', "\0", "\n", "\r", "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'], $string);
137
-    }
138
-
139
-    /**
140
-     * @param mixed $str
141
-     * @return string
142
-     */
143
-    public function dbAddslashes($str = '')
144
-    {
145
-        if (!isset($str) || $str == '') {
146
-            return '';
147
-        }
148
-        return addslashes($str);
149
-    }
150
-
151
-    /**
152
-     * Db::toTimestamp()
153
-     * @param mixed $epoch
154
-     * @return bool|string
155
-     */
156
-    public function toTimestamp($epoch)
157
-    {
158
-        return date('Y-m-d H:i:s', is_float($epoch) ? intval($epoch) : $epoch);
159
-    }
160
-
161
-    /**
162
-     * Db::fromTimestamp()
163
-     * @param mixed $timestamp
164
-     * @return bool|int|mixed
165
-     */
166
-    public function fromTimestamp($timestamp)
167
-    {
168
-        if (preg_match('/([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $timestamp, $parts)) {
169
-            $time = mktime($parts[4], $parts[5], $parts[6], $parts[2], $parts[3], $parts[1]);
170
-        } elseif (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $timestamp, $parts)) {
171
-            $time = mktime($parts[4], $parts[5], $parts[6], $parts[2], $parts[3], $parts[1]);
172
-        } elseif (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})/', $timestamp, $parts)) {
173
-            $time = mktime(1, 1, 1, $parts[2], $parts[3], $parts[1]);
174
-        } elseif (is_numeric($timestamp) && $timestamp >= 943938000) {
175
-            $time = $timestamp;
176
-        } else {
177
-            $this->log('Cannot Match Timestamp from '.$timestamp, __LINE__, __FILE__);
178
-            $time = false;
179
-        }
180
-        return $time;
181
-    }
182
-
183
-    /**
184
-     * perform a query with limited result set
185
-     *
186
-     * @param string $queryString
187
-     * @param string|int $numRows
188
-     * @param int $offset
189
-     * @param string|int $line
190
-     * @param string $file
191
-     * @return mixed
192
-     */
193
-    public function limitQuery($queryString, $numRows = '', $offset = 0, $line = '', $file = '')
194
-    {
195
-        if (!$numRows) {
196
-            $numRows = $this->maxMatches;
197
-        }
198
-        if ($offset == 0) {
199
-            $queryString .= ' LIMIT '.(int) $numRows;
200
-        } else {
201
-            $queryString .= ' LIMIT '.(int) $offset.','.(int) $numRows;
202
-        }
203
-
204
-        if ($this->Debug) {
205
-            printf("Debug: limitQuery = %s<br>offset=%d, num_rows=%d<br>\n", $queryString, $offset, $numRows);
206
-        }
207
-
208
-        return $this->query($queryString, $line, $file);
209
-    }
210
-
211
-    /**
212
-     * db:qr()
213
-     *
214
-     *  alias of queryReturn()
215
-     *
216
-     * @param mixed $query SQL Query to be used
217
-     * @param string $line optionally pass __LINE__ calling the query for logging
218
-     * @param string $file optionally pass __FILE__ calling the query for logging
219
-     * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
220
-     */
221
-    public function qr($query, $line = '', $file = '')
222
-    {
223
-        return $this->queryReturn($query, $line, $file);
224
-    }
225
-
226
-    /**
227
-     * gets a field
228
-     *
229
-     * @param mixed  $name
230
-     * @param string $stripSlashes
231
-     * @return string
232
-     */
233
-    public function f($name, $stripSlashes = '')
234
-    {
235
-        if (is_null($this->Record)) {
236
-            return null;
237
-        } elseif ($stripSlashes || ($this->autoStripslashes && !$stripSlashes)) {
238
-            return stripslashes($this->Record[$name]);
239
-        } else {
240
-            return $this->Record[$name];
241
-        }
242
-    }
243
-
244
-    /**
245
-     * error handling
246
-     *
247
-     * @param mixed $msg
248
-     * @param string $line
249
-     * @param string $file
250
-     * @return void
251
-     */
252
-    public function halt($msg, $line = '', $file = '')
253
-    {
254
-        $this->unlock(false);
255
-        /* Just in case there is a table currently locked */
256
-
257
-        //$this->Error = @$this->linkId->error;
258
-        //$this->Errno = @$this->linkId->errno;
259
-        if ($this->haltOnError == 'no') {
260
-            return true;
261
-        }
262
-        if ($msg != '') {
263
-            $this->haltmsg($msg, $line, $file);
264
-        }
265
-        if ($this->haltOnError != 'report') {
266
-            echo '<p><b>Session halted.</b>';
267
-            //if (isset($GLOBALS['tf']))
268
-            //$GLOBALS['tf']->terminate();
269
-            die();
270
-        }
271
-        return true;
272
-    }
273
-
274
-    /**
275
-     * @param mixed $msg
276
-     * @param string $line
277
-     * @param string $file
278
-     * @return mixed|void
279
-     */
280
-    public function logBackTrace($msg, $line = '', $file = '')
281
-    {
282
-        $backtrace = (function_exists('debug_backtrace') ? debug_backtrace() : []);
283
-        $this->log(
284
-            ('' !== getenv('REQUEST_URI') ? ' '.getenv('REQUEST_URI') : '').
285
-            ((isset($_POST) && count($_POST)) ? ' POST='.json_encode($_POST) : '').
286
-            ((isset($_GET) && count($_GET)) ? ' GET='.json_encode($_GET) : '').
287
-            ((isset($_FILES) && count($_FILES)) ? ' FILES='.json_encode($_FILES) : '').
288
-            ('' !== getenv('HTTP_USER_AGENT') ? ' AGENT="'.getenv('HTTP_USER_AGENT').'"' : '').
289
-            (isset($_SERVER['REQUEST_METHOD']) ? ' METHOD="'.$_SERVER['REQUEST_METHOD'].'"'.
290
-                ($_SERVER['REQUEST_METHOD'] === 'POST' ? ' POST="'.json_encode($_POST).'"' : '') : ''),
291
-            $line,
292
-            $file,
293
-            'error'
294
-        );
295
-        for ($level = 1, $levelMax = count($backtrace); $level < $levelMax; $level++) {
296
-            $message = (isset($backtrace[$level]['file']) ? 'File: '.$backtrace[$level]['file'] : '').
297
-                (isset($backtrace[$level]['line']) ? ' Line: '.$backtrace[$level]['line'] : '').
298
-                ' Function: '.(isset($backtrace[$level] ['class']) ? '(class '.$backtrace[$level] ['class'].') ' : '').
299
-                (isset($backtrace[$level] ['type']) ? $backtrace[$level] ['type'].' ' : '').
300
-                $backtrace[$level] ['function'].'(';
301
-            if (isset($backtrace[$level] ['args'])) {
302
-                for ($argument = 0, $argumentMax = count($backtrace[$level]['args']); $argument < $argumentMax; $argument++) {
303
-                    $message .= ($argument > 0 ? ', ' : '').
304
-                        (is_object($backtrace[$level]['args'][$argument]) ? 'class '.get_class($backtrace[$level]['args'][$argument]) : json_encode($backtrace[$level]['args'][$argument]));
305
-                }
306
-            }
307
-            $message .= ')';
308
-            $this->log($message, $line, $file, 'error');
309
-        }
310
-    }
311
-
312
-    public function emailError($queryString, $error, $line, $file)
313
-    {
314
-        $subject = php_uname('n').' MySQLi Error '.$queryString;
315
-        if (class_exists('\\TFSmarty')) {
316
-            $smarty = new \TFSmarty();
317
-            $smarty->assign([
318
-                'type' => $this->type,
319
-                'queryString' => $queryString,
320
-                'error' => $error,
321
-                'line' => $line,
322
-                'file' => $file,
323
-                'request' => $_REQUEST,
324
-                'server' => $_SERVER,
325
-            ]);
326
-            if (isset($GLOBALS['tf'])) {
327
-                $smarty->assign('account_id', $GLOBALS['tf']->session->account_id);
328
-            }
329
-            $email = $smarty->fetch('email/admin/sql_error.tpl');
330
-            (new \MyAdmin\Mail())->adminMail($subject, $email, '[email protected]', '');
331
-            (new \MyAdmin\Mail())->adminMail($subject, $email, '[email protected]', '');
332
-        }
333
-        $this->haltmsg('Invalid SQL: '.$queryString, $line, $file);
334
-    }
335
-
336
-    /**
337
-     * @param mixed $msg
338
-     * @param string $line
339
-     * @param string $file
340
-     * @return mixed|void
341
-     */
342
-    public function haltmsg($msg, $line = '', $file = '')
343
-    {
344
-        $email = "DB Error {$msg} {$file}:{$line}";
345
-        if (class_exists('\\MyAdmin\Mail')) {
346
-            \MyAdmin\Mail::failsafeMail($email, $email, ['[email protected]', '[email protected]']);
347
-            return;
348
-        }
349
-        $this->log("Database error: $msg", $line, $file, 'error');
350
-        if ($this->Errno != '0' || !in_array($this->Error, ['', '()'])) {
351
-            $sqlstate = mysqli_sqlstate($this->linkId);
352
-            $this->log("MySQLi SQLState: {$sqlstate}. Error: ".$this->Errno.' ('.$this->Error.')', $line, $file, 'error');
353
-        }
354
-        $this->logBackTrace($msg, $line, $file);
355
-    }
356
-
357
-    /**
358
-     * @return array
359
-     */
360
-    public function indexNames()
361
-    {
362
-        return [];
363
-    }
364
-
365
-
366
-    /**
367
-     * Add query to logged queries.
368
-     * @param string $statement
369
-     * @param float $time Elapsed seconds with microseconds
370
-     * @param string|int $line Line Number
371
-     * @param string $file File Name
372
-     */
373
-    public function addLog($statement, $time, $line = '', $file = '')
374
-    {
375
-        $query = [
376
-            'statement' => $statement,
377
-            'time' => $time * 1000
378
-        ];
379
-        if ($line != '') {
380
-            $query['line'] = $line;
381
-        }
382
-        if ($file != '') {
383
-            $query['file'] = $file;
384
-        }
385
-        if (!isset($GLOBALS['db_queries'])) {
386
-            $GLOBALS['db_queries'] = [];
387
-        }
388
-        $GLOBALS['db_queries'][] = $query;
389
-        array_push($this->log, $query);
390
-    }
391
-
392
-    /**
393
-     * Return logged queries.
394
-     * @return array Logged queries
395
-     */
396
-    public function getLog()
397
-    {
398
-        return $this->log;
399
-    }
17
+	/* public: connection parameters */
18
+	public $host = 'localhost';
19
+	public $database = '';
20
+	public $user = '';
21
+	public $password = '';
22
+	public $port = '';
23
+
24
+	/* public: configuration parameters */
25
+	public $autoStripslashes = false;
26
+	public $Debug = 0; // Set to 1 for debugging messages.
27
+	public $haltOnError = 'yes'; // "yes" (halt with message), "no" (ignore errors quietly), "report" (ignore error, but spit a warning)
28
+
29
+	public $maxConnectErrors = 5;
30
+	public $connectionAttempt = 0;
31
+	public $maxMatches = 10000000;
32
+
33
+	public $Type = 'mysql';
34
+
35
+	/**
36
+	 * @var int
37
+	 */
38
+	public $autoFree = 0; // Set to 1 for automatic mysql_free_result()
39
+
40
+	/* public: result array and current row number */
41
+	public $Record = [];
42
+	public $Row;
43
+
44
+	/* public: current error number and error text */
45
+	public $Errno = 0;
46
+	public $Error = '';
47
+
48
+	/* public: this is an api revision, not a CVS revision. */
49
+	public $type = 'generic';
50
+
51
+	/**
52
+	 * @var int|object
53
+	 */
54
+	public $linkId = 0;
55
+	public $queryId = 0;
56
+
57
+	public $characterSet = 'utf8mb4';
58
+	public $collation = 'utf8mb4_unicode_ci';
59
+
60
+	/**
61
+	 * Logged queries.
62
+	 * @var array
63
+	 */
64
+	protected $log = [];
65
+
66
+	/**
67
+	 * Constructs the db handler, can optionally specify connection parameters
68
+	 *
69
+	 * @param string $database Optional The database name
70
+	 * @param string $user Optional The username to connect with
71
+	 * @param string $password Optional The password to use
72
+	 * @param string $host Optional The hostname where the server is, or default to localhost
73
+	 * @param string $query Optional query to perform immediately
74
+	 * @param string $port optional port for the connection
75
+	 */
76
+	public function __construct($database = '', $user = '', $password = '', $host = 'localhost', $query = '', $port = '')
77
+	{
78
+		$this->database = $database;
79
+		$this->user = $user;
80
+		$this->password = $password;
81
+		$this->host = $host;
82
+		$this->port = $port;
83
+		if ($query != '') {
84
+			$this->query($query);
85
+		}
86
+		$this->connectionAttempt = 0;
87
+	}
88
+
89
+	/**
90
+	 * @param string $message
91
+	 * @param string $line
92
+	 * @param string $file
93
+	 * @return void
94
+	 */
95
+	public function log($message, $line = '', $file = '', $level = 'info')
96
+	{
97
+		error_log('SQL Query '.$line.' '.$file.' '.$message);
98
+	}
99
+
100
+	/**
101
+	 * @return int|object
102
+	 */
103
+	public function linkId()
104
+	{
105
+		return $this->linkId;
106
+	}
107
+
108
+	/**
109
+	 * @return int|object
110
+	 */
111
+	public function queryId()
112
+	{
113
+		return $this->queryId;
114
+	}
115
+
116
+	/**
117
+	 * @param $string
118
+	 * @return string
119
+	 */
120
+	public function real_escape($string = '')
121
+	{
122
+		if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect()) {
123
+			return $this->escape($string);
124
+		}
125
+		return mysqli_real_escape_string($this->linkId, $string);
126
+	}
127
+
128
+	/**
129
+	 * @param $string
130
+	 * @return string
131
+	 */
132
+	public function escape($string = '')
133
+	{
134
+		//if (function_exists('mysql_escape_string'))
135
+		//return mysql_escape_string($string);
136
+		return str_replace(['\\', "\0", "\n", "\r", "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'], $string);
137
+	}
138
+
139
+	/**
140
+	 * @param mixed $str
141
+	 * @return string
142
+	 */
143
+	public function dbAddslashes($str = '')
144
+	{
145
+		if (!isset($str) || $str == '') {
146
+			return '';
147
+		}
148
+		return addslashes($str);
149
+	}
150
+
151
+	/**
152
+	 * Db::toTimestamp()
153
+	 * @param mixed $epoch
154
+	 * @return bool|string
155
+	 */
156
+	public function toTimestamp($epoch)
157
+	{
158
+		return date('Y-m-d H:i:s', is_float($epoch) ? intval($epoch) : $epoch);
159
+	}
160
+
161
+	/**
162
+	 * Db::fromTimestamp()
163
+	 * @param mixed $timestamp
164
+	 * @return bool|int|mixed
165
+	 */
166
+	public function fromTimestamp($timestamp)
167
+	{
168
+		if (preg_match('/([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $timestamp, $parts)) {
169
+			$time = mktime($parts[4], $parts[5], $parts[6], $parts[2], $parts[3], $parts[1]);
170
+		} elseif (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $timestamp, $parts)) {
171
+			$time = mktime($parts[4], $parts[5], $parts[6], $parts[2], $parts[3], $parts[1]);
172
+		} elseif (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})/', $timestamp, $parts)) {
173
+			$time = mktime(1, 1, 1, $parts[2], $parts[3], $parts[1]);
174
+		} elseif (is_numeric($timestamp) && $timestamp >= 943938000) {
175
+			$time = $timestamp;
176
+		} else {
177
+			$this->log('Cannot Match Timestamp from '.$timestamp, __LINE__, __FILE__);
178
+			$time = false;
179
+		}
180
+		return $time;
181
+	}
182
+
183
+	/**
184
+	 * perform a query with limited result set
185
+	 *
186
+	 * @param string $queryString
187
+	 * @param string|int $numRows
188
+	 * @param int $offset
189
+	 * @param string|int $line
190
+	 * @param string $file
191
+	 * @return mixed
192
+	 */
193
+	public function limitQuery($queryString, $numRows = '', $offset = 0, $line = '', $file = '')
194
+	{
195
+		if (!$numRows) {
196
+			$numRows = $this->maxMatches;
197
+		}
198
+		if ($offset == 0) {
199
+			$queryString .= ' LIMIT '.(int) $numRows;
200
+		} else {
201
+			$queryString .= ' LIMIT '.(int) $offset.','.(int) $numRows;
202
+		}
203
+
204
+		if ($this->Debug) {
205
+			printf("Debug: limitQuery = %s<br>offset=%d, num_rows=%d<br>\n", $queryString, $offset, $numRows);
206
+		}
207
+
208
+		return $this->query($queryString, $line, $file);
209
+	}
210
+
211
+	/**
212
+	 * db:qr()
213
+	 *
214
+	 *  alias of queryReturn()
215
+	 *
216
+	 * @param mixed $query SQL Query to be used
217
+	 * @param string $line optionally pass __LINE__ calling the query for logging
218
+	 * @param string $file optionally pass __FILE__ calling the query for logging
219
+	 * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
220
+	 */
221
+	public function qr($query, $line = '', $file = '')
222
+	{
223
+		return $this->queryReturn($query, $line, $file);
224
+	}
225
+
226
+	/**
227
+	 * gets a field
228
+	 *
229
+	 * @param mixed  $name
230
+	 * @param string $stripSlashes
231
+	 * @return string
232
+	 */
233
+	public function f($name, $stripSlashes = '')
234
+	{
235
+		if (is_null($this->Record)) {
236
+			return null;
237
+		} elseif ($stripSlashes || ($this->autoStripslashes && !$stripSlashes)) {
238
+			return stripslashes($this->Record[$name]);
239
+		} else {
240
+			return $this->Record[$name];
241
+		}
242
+	}
243
+
244
+	/**
245
+	 * error handling
246
+	 *
247
+	 * @param mixed $msg
248
+	 * @param string $line
249
+	 * @param string $file
250
+	 * @return void
251
+	 */
252
+	public function halt($msg, $line = '', $file = '')
253
+	{
254
+		$this->unlock(false);
255
+		/* Just in case there is a table currently locked */
256
+
257
+		//$this->Error = @$this->linkId->error;
258
+		//$this->Errno = @$this->linkId->errno;
259
+		if ($this->haltOnError == 'no') {
260
+			return true;
261
+		}
262
+		if ($msg != '') {
263
+			$this->haltmsg($msg, $line, $file);
264
+		}
265
+		if ($this->haltOnError != 'report') {
266
+			echo '<p><b>Session halted.</b>';
267
+			//if (isset($GLOBALS['tf']))
268
+			//$GLOBALS['tf']->terminate();
269
+			die();
270
+		}
271
+		return true;
272
+	}
273
+
274
+	/**
275
+	 * @param mixed $msg
276
+	 * @param string $line
277
+	 * @param string $file
278
+	 * @return mixed|void
279
+	 */
280
+	public function logBackTrace($msg, $line = '', $file = '')
281
+	{
282
+		$backtrace = (function_exists('debug_backtrace') ? debug_backtrace() : []);
283
+		$this->log(
284
+			('' !== getenv('REQUEST_URI') ? ' '.getenv('REQUEST_URI') : '').
285
+			((isset($_POST) && count($_POST)) ? ' POST='.json_encode($_POST) : '').
286
+			((isset($_GET) && count($_GET)) ? ' GET='.json_encode($_GET) : '').
287
+			((isset($_FILES) && count($_FILES)) ? ' FILES='.json_encode($_FILES) : '').
288
+			('' !== getenv('HTTP_USER_AGENT') ? ' AGENT="'.getenv('HTTP_USER_AGENT').'"' : '').
289
+			(isset($_SERVER['REQUEST_METHOD']) ? ' METHOD="'.$_SERVER['REQUEST_METHOD'].'"'.
290
+				($_SERVER['REQUEST_METHOD'] === 'POST' ? ' POST="'.json_encode($_POST).'"' : '') : ''),
291
+			$line,
292
+			$file,
293
+			'error'
294
+		);
295
+		for ($level = 1, $levelMax = count($backtrace); $level < $levelMax; $level++) {
296
+			$message = (isset($backtrace[$level]['file']) ? 'File: '.$backtrace[$level]['file'] : '').
297
+				(isset($backtrace[$level]['line']) ? ' Line: '.$backtrace[$level]['line'] : '').
298
+				' Function: '.(isset($backtrace[$level] ['class']) ? '(class '.$backtrace[$level] ['class'].') ' : '').
299
+				(isset($backtrace[$level] ['type']) ? $backtrace[$level] ['type'].' ' : '').
300
+				$backtrace[$level] ['function'].'(';
301
+			if (isset($backtrace[$level] ['args'])) {
302
+				for ($argument = 0, $argumentMax = count($backtrace[$level]['args']); $argument < $argumentMax; $argument++) {
303
+					$message .= ($argument > 0 ? ', ' : '').
304
+						(is_object($backtrace[$level]['args'][$argument]) ? 'class '.get_class($backtrace[$level]['args'][$argument]) : json_encode($backtrace[$level]['args'][$argument]));
305
+				}
306
+			}
307
+			$message .= ')';
308
+			$this->log($message, $line, $file, 'error');
309
+		}
310
+	}
311
+
312
+	public function emailError($queryString, $error, $line, $file)
313
+	{
314
+		$subject = php_uname('n').' MySQLi Error '.$queryString;
315
+		if (class_exists('\\TFSmarty')) {
316
+			$smarty = new \TFSmarty();
317
+			$smarty->assign([
318
+				'type' => $this->type,
319
+				'queryString' => $queryString,
320
+				'error' => $error,
321
+				'line' => $line,
322
+				'file' => $file,
323
+				'request' => $_REQUEST,
324
+				'server' => $_SERVER,
325
+			]);
326
+			if (isset($GLOBALS['tf'])) {
327
+				$smarty->assign('account_id', $GLOBALS['tf']->session->account_id);
328
+			}
329
+			$email = $smarty->fetch('email/admin/sql_error.tpl');
330
+			(new \MyAdmin\Mail())->adminMail($subject, $email, '[email protected]', '');
331
+			(new \MyAdmin\Mail())->adminMail($subject, $email, '[email protected]', '');
332
+		}
333
+		$this->haltmsg('Invalid SQL: '.$queryString, $line, $file);
334
+	}
335
+
336
+	/**
337
+	 * @param mixed $msg
338
+	 * @param string $line
339
+	 * @param string $file
340
+	 * @return mixed|void
341
+	 */
342
+	public function haltmsg($msg, $line = '', $file = '')
343
+	{
344
+		$email = "DB Error {$msg} {$file}:{$line}";
345
+		if (class_exists('\\MyAdmin\Mail')) {
346
+			\MyAdmin\Mail::failsafeMail($email, $email, ['[email protected]', '[email protected]']);
347
+			return;
348
+		}
349
+		$this->log("Database error: $msg", $line, $file, 'error');
350
+		if ($this->Errno != '0' || !in_array($this->Error, ['', '()'])) {
351
+			$sqlstate = mysqli_sqlstate($this->linkId);
352
+			$this->log("MySQLi SQLState: {$sqlstate}. Error: ".$this->Errno.' ('.$this->Error.')', $line, $file, 'error');
353
+		}
354
+		$this->logBackTrace($msg, $line, $file);
355
+	}
356
+
357
+	/**
358
+	 * @return array
359
+	 */
360
+	public function indexNames()
361
+	{
362
+		return [];
363
+	}
364
+
365
+
366
+	/**
367
+	 * Add query to logged queries.
368
+	 * @param string $statement
369
+	 * @param float $time Elapsed seconds with microseconds
370
+	 * @param string|int $line Line Number
371
+	 * @param string $file File Name
372
+	 */
373
+	public function addLog($statement, $time, $line = '', $file = '')
374
+	{
375
+		$query = [
376
+			'statement' => $statement,
377
+			'time' => $time * 1000
378
+		];
379
+		if ($line != '') {
380
+			$query['line'] = $line;
381
+		}
382
+		if ($file != '') {
383
+			$query['file'] = $file;
384
+		}
385
+		if (!isset($GLOBALS['db_queries'])) {
386
+			$GLOBALS['db_queries'] = [];
387
+		}
388
+		$GLOBALS['db_queries'][] = $query;
389
+		array_push($this->log, $query);
390
+	}
391
+
392
+	/**
393
+	 * Return logged queries.
394
+	 * @return array Logged queries
395
+	 */
396
+	public function getLog()
397
+	{
398
+		return $this->log;
399
+	}
400 400
 }
Please login to merge, or discard this patch.
Braces   +20 added lines, -40 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@  discard block
 block discarded – undo
12 12
 /**
13 13
  * Class Generic
14 14
  */
15
-abstract class Generic
16
-{
15
+abstract class Generic {
17 16
     /* public: connection parameters */
18 17
     public $host = 'localhost';
19 18
     public $database = '';
@@ -73,8 +72,7 @@  discard block
 block discarded – undo
73 72
      * @param string $query Optional query to perform immediately
74 73
      * @param string $port optional port for the connection
75 74
      */
76
-    public function __construct($database = '', $user = '', $password = '', $host = 'localhost', $query = '', $port = '')
77
-    {
75
+    public function __construct($database = '', $user = '', $password = '', $host = 'localhost', $query = '', $port = '') {
78 76
         $this->database = $database;
79 77
         $this->user = $user;
80 78
         $this->password = $password;
@@ -92,24 +90,21 @@  discard block
 block discarded – undo
92 90
      * @param string $file
93 91
      * @return void
94 92
      */
95
-    public function log($message, $line = '', $file = '', $level = 'info')
96
-    {
93
+    public function log($message, $line = '', $file = '', $level = 'info') {
97 94
         error_log('SQL Query '.$line.' '.$file.' '.$message);
98 95
     }
99 96
 
100 97
     /**
101 98
      * @return int|object
102 99
      */
103
-    public function linkId()
104
-    {
100
+    public function linkId() {
105 101
         return $this->linkId;
106 102
     }
107 103
 
108 104
     /**
109 105
      * @return int|object
110 106
      */
111
-    public function queryId()
112
-    {
107
+    public function queryId() {
113 108
         return $this->queryId;
114 109
     }
115 110
 
@@ -117,8 +112,7 @@  discard block
 block discarded – undo
117 112
      * @param $string
118 113
      * @return string
119 114
      */
120
-    public function real_escape($string = '')
121
-    {
115
+    public function real_escape($string = '') {
122 116
         if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect()) {
123 117
             return $this->escape($string);
124 118
         }
@@ -129,8 +123,7 @@  discard block
 block discarded – undo
129 123
      * @param $string
130 124
      * @return string
131 125
      */
132
-    public function escape($string = '')
133
-    {
126
+    public function escape($string = '') {
134 127
         //if (function_exists('mysql_escape_string'))
135 128
         //return mysql_escape_string($string);
136 129
         return str_replace(['\\', "\0", "\n", "\r", "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'], $string);
@@ -140,8 +133,7 @@  discard block
 block discarded – undo
140 133
      * @param mixed $str
141 134
      * @return string
142 135
      */
143
-    public function dbAddslashes($str = '')
144
-    {
136
+    public function dbAddslashes($str = '') {
145 137
         if (!isset($str) || $str == '') {
146 138
             return '';
147 139
         }
@@ -153,8 +145,7 @@  discard block
 block discarded – undo
153 145
      * @param mixed $epoch
154 146
      * @return bool|string
155 147
      */
156
-    public function toTimestamp($epoch)
157
-    {
148
+    public function toTimestamp($epoch) {
158 149
         return date('Y-m-d H:i:s', is_float($epoch) ? intval($epoch) : $epoch);
159 150
     }
160 151
 
@@ -163,8 +154,7 @@  discard block
 block discarded – undo
163 154
      * @param mixed $timestamp
164 155
      * @return bool|int|mixed
165 156
      */
166
-    public function fromTimestamp($timestamp)
167
-    {
157
+    public function fromTimestamp($timestamp) {
168 158
         if (preg_match('/([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $timestamp, $parts)) {
169 159
             $time = mktime($parts[4], $parts[5], $parts[6], $parts[2], $parts[3], $parts[1]);
170 160
         } elseif (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $timestamp, $parts)) {
@@ -190,8 +180,7 @@  discard block
 block discarded – undo
190 180
      * @param string $file
191 181
      * @return mixed
192 182
      */
193
-    public function limitQuery($queryString, $numRows = '', $offset = 0, $line = '', $file = '')
194
-    {
183
+    public function limitQuery($queryString, $numRows = '', $offset = 0, $line = '', $file = '') {
195 184
         if (!$numRows) {
196 185
             $numRows = $this->maxMatches;
197 186
         }
@@ -218,8 +207,7 @@  discard block
 block discarded – undo
218 207
      * @param string $file optionally pass __FILE__ calling the query for logging
219 208
      * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
220 209
      */
221
-    public function qr($query, $line = '', $file = '')
222
-    {
210
+    public function qr($query, $line = '', $file = '') {
223 211
         return $this->queryReturn($query, $line, $file);
224 212
     }
225 213
 
@@ -230,8 +218,7 @@  discard block
 block discarded – undo
230 218
      * @param string $stripSlashes
231 219
      * @return string
232 220
      */
233
-    public function f($name, $stripSlashes = '')
234
-    {
221
+    public function f($name, $stripSlashes = '') {
235 222
         if (is_null($this->Record)) {
236 223
             return null;
237 224
         } elseif ($stripSlashes || ($this->autoStripslashes && !$stripSlashes)) {
@@ -249,8 +236,7 @@  discard block
 block discarded – undo
249 236
      * @param string $file
250 237
      * @return void
251 238
      */
252
-    public function halt($msg, $line = '', $file = '')
253
-    {
239
+    public function halt($msg, $line = '', $file = '') {
254 240
         $this->unlock(false);
255 241
         /* Just in case there is a table currently locked */
256 242
 
@@ -277,8 +263,7 @@  discard block
 block discarded – undo
277 263
      * @param string $file
278 264
      * @return mixed|void
279 265
      */
280
-    public function logBackTrace($msg, $line = '', $file = '')
281
-    {
266
+    public function logBackTrace($msg, $line = '', $file = '') {
282 267
         $backtrace = (function_exists('debug_backtrace') ? debug_backtrace() : []);
283 268
         $this->log(
284 269
             ('' !== getenv('REQUEST_URI') ? ' '.getenv('REQUEST_URI') : '').
@@ -309,8 +294,7 @@  discard block
 block discarded – undo
309 294
         }
310 295
     }
311 296
 
312
-    public function emailError($queryString, $error, $line, $file)
313
-    {
297
+    public function emailError($queryString, $error, $line, $file) {
314 298
         $subject = php_uname('n').' MySQLi Error '.$queryString;
315 299
         if (class_exists('\\TFSmarty')) {
316 300
             $smarty = new \TFSmarty();
@@ -339,8 +323,7 @@  discard block
 block discarded – undo
339 323
      * @param string $file
340 324
      * @return mixed|void
341 325
      */
342
-    public function haltmsg($msg, $line = '', $file = '')
343
-    {
326
+    public function haltmsg($msg, $line = '', $file = '') {
344 327
         $email = "DB Error {$msg} {$file}:{$line}";
345 328
         if (class_exists('\\MyAdmin\Mail')) {
346 329
             \MyAdmin\Mail::failsafeMail($email, $email, ['[email protected]', '[email protected]']);
@@ -357,8 +340,7 @@  discard block
 block discarded – undo
357 340
     /**
358 341
      * @return array
359 342
      */
360
-    public function indexNames()
361
-    {
343
+    public function indexNames() {
362 344
         return [];
363 345
     }
364 346
 
@@ -370,8 +352,7 @@  discard block
 block discarded – undo
370 352
      * @param string|int $line Line Number
371 353
      * @param string $file File Name
372 354
      */
373
-    public function addLog($statement, $time, $line = '', $file = '')
374
-    {
355
+    public function addLog($statement, $time, $line = '', $file = '') {
375 356
         $query = [
376 357
             'statement' => $statement,
377 358
             'time' => $time * 1000
@@ -393,8 +374,7 @@  discard block
 block discarded – undo
393 374
      * Return logged queries.
394 375
      * @return array Logged queries
395 376
      */
396
-    public function getLog()
397
-    {
377
+    public function getLog() {
398 378
         return $this->log;
399 379
     }
400 380
 }
Please login to merge, or discard this patch.
src/Mysqli/Db.php 4 patches
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@
 block discarded – undo
88 88
             //error_log("real_connect($host, $user, $password, $database, $port)");
89 89
             $this->linkId = mysqli_init();
90 90
             $this->linkId->options(MYSQLI_INIT_COMMAND, "SET NAMES {$this->characterSet} COLLATE {$this->collation}, COLLATION_CONNECTION = {$this->collation}, COLLATION_DATABASE = {$this->collation}");
91
-            if (!$this->linkId->real_connect($host, $user, $password, $database, $port != '' ? $port : NULL)) {
91
+            if (!$this->linkId->real_connect($host, $user, $password, $database, $port != '' ? $port : null)) {
92 92
                 $this->halt("connect($host, $user, \$password) failed. ".(is_object($this->linkId) && isset( $this->linkId->connect_error) ? $this->linkId->connect_error : ''));
93 93
                 return 0;
94 94
             }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -86,19 +86,19 @@  discard block
 block discarded – undo
86 86
                 exit;
87 87
             }
88 88
             if ($this->connectionAttempt >= $this->maxConnectErrors) {
89
-                $this->halt("connect($host, $user, \$password) failed. ".(is_object($this->linkId) && isset( $this->linkId->connect_error) ? $this->linkId->connect_error : ''));
89
+                $this->halt("connect($host, $user, \$password) failed. ".(is_object($this->linkId) && isset($this->linkId->connect_error) ? $this->linkId->connect_error : ''));
90 90
                 return 0;
91 91
             }
92 92
             //error_log("real_connect($host, $user, $password, $database, $port)");
93 93
             $this->linkId = mysqli_init();
94 94
             $this->linkId->options(MYSQLI_INIT_COMMAND, "SET NAMES {$this->characterSet} COLLATE {$this->collation}, COLLATION_CONNECTION = {$this->collation}, COLLATION_DATABASE = {$this->collation}");
95 95
             if (!$this->linkId->real_connect($host, $user, $password, $database, $port != '' ? $port : NULL)) {
96
-                $this->halt("connect($host, $user, \$password) failed. ".(is_object($this->linkId) && isset( $this->linkId->connect_error) ? $this->linkId->connect_error : ''));
96
+                $this->halt("connect($host, $user, \$password) failed. ".(is_object($this->linkId) && isset($this->linkId->connect_error) ? $this->linkId->connect_error : ''));
97 97
                 return 0;
98 98
             }
99 99
             $this->linkId->set_charset($this->characterSet);
100 100
             if ($this->linkId->connect_errno) {
101
-                $this->halt("connect($host, $user, \$password) failed. ".(is_object($this->linkId) && isset( $this->linkId->connect_error) ? $this->linkId->connect_error : ''));
101
+                $this->halt("connect($host, $user, \$password) failed. ".(is_object($this->linkId) && isset($this->linkId->connect_error) ? $this->linkId->connect_error : ''));
102 102
                 return 0;
103 103
             }
104 104
         }
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
         $return = mysqli_stmt_execute($this->statement);
234 234
         if (!isset($GLOBALS['disable_db_queries'])) {
235 235
             $vars = $this->statement_vars;
236
-            $query = $result = preg_replace_callback('/\?/', function () use (&$vars) {
236
+            $query = $result = preg_replace_callback('/\?/', function() use (&$vars) {
237 237
                 return array_shift($vars);
238 238
                 }, $this->statement_query);
239 239
             $this->addLog($query, microtime(true) - $start, $line, $file);
@@ -295,24 +295,24 @@  discard block
 block discarded – undo
295 295
                 $fails++;
296 296
                 try {
297 297
                     $this->queryId = @mysqli_query($this->linkId, $queryString, MYSQLI_STORE_RESULT);
298
-                    if (in_array((int)@mysqli_errno($this->linkId), [1213, 2006, 3101, 1180])) {
298
+                    if (in_array((int) @mysqli_errno($this->linkId), [1213, 2006, 3101, 1180])) {
299 299
                         //error_log("got ".@mysqli_errno($this->linkId)." sql error fails {$fails} on query {$queryString} from {$line}:{$file}");
300 300
                         usleep(250000); // 0.25 second
301 301
                     } else {
302 302
                         $onlyRollback = false;
303
-                        if (in_array((int)@mysqli_errno($this->linkId), [1064])) {
303
+                        if (in_array((int) @mysqli_errno($this->linkId), [1064])) {
304 304
                             $tries = 0;
305 305
                         }
306 306
                         break;
307 307
                     }
308 308
                 } catch (\mysqli_sql_exception $e) {
309
-                    if (in_array((int)$e->getCode(), [1213, 2006, 3101, 1180])) {
309
+                    if (in_array((int) $e->getCode(), [1213, 2006, 3101, 1180])) {
310 310
                         //error_log("got ".$e->getCode()." sql error fails {$fails}");
311 311
                         usleep(250000); // 0.25 second
312 312
                     } else {
313 313
                         error_log('Got mysqli_sql_exception code '.$e->getCode().' error '.$e->getMessage().' on query '.$queryString.' from '.$line.':'.$file);
314 314
                         $onlyRollback = false;
315
-                        if (in_array((int)@mysqli_errno($this->linkId), [1064])) {
315
+                        if (in_array((int) @mysqli_errno($this->linkId), [1064])) {
316 316
                             $tries = 0;
317 317
                         }
318 318
                         break;
Please login to merge, or discard this patch.
Braces   +24 added lines, -48 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
     /**
23 22
     * @var string
24 23
     */
@@ -33,8 +32,7 @@  discard block
 block discarded – undo
33 32
     * @param string $database the name of the database to use
34 33
     * @return void
35 34
     */
36
-    public function useDb($database)
37
-    {
35
+    public function useDb($database) {
38 36
         $this->selectDb($database);
39 37
     }
40 38
 
@@ -44,8 +42,7 @@  discard block
 block discarded – undo
44 42
     * @param string $database the name of the database to use
45 43
     * @return void
46 44
     */
47
-    public function selectDb($database)
48
-    {
45
+    public function selectDb($database) {
49 46
         $this->connect();
50 47
         mysqli_select_db($this->linkId, $database);
51 48
     }
@@ -60,8 +57,7 @@  discard block
 block discarded – undo
60 57
     * @param string $password
61 58
     * @return int|\mysqli
62 59
     */
63
-    public function connect($database = '', $host = '', $user = '', $password = '', $port = '')
64
-    {
60
+    public function connect($database = '', $host = '', $user = '', $password = '', $port = '') {
65 61
         /* Handle defaults */
66 62
         if ($database == '') {
67 63
             $database = $this->database;
@@ -109,8 +105,7 @@  discard block
 block discarded – undo
109 105
     * Db::disconnect()
110 106
     * @return bool
111 107
     */
112
-    public function disconnect()
113
-    {
108
+    public function disconnect() {
114 109
         $return = !is_int($this->linkId) && method_exists($this->linkId, 'close') ? $this->linkId->close() : false;
115 110
         $this->linkId = 0;
116 111
         return $return;
@@ -120,8 +115,7 @@  discard block
 block discarded – undo
120 115
     * @param $string
121 116
     * @return string
122 117
     */
123
-    public function real_escape($string = '')
124
-    {
118
+    public function real_escape($string = '') {
125 119
         if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect()) {
126 120
             return $this->escape($string);
127 121
         }
@@ -132,8 +126,7 @@  discard block
 block discarded – undo
132 126
     * discard the query result
133 127
     * @return void
134 128
     */
135
-    public function free()
136
-    {
129
+    public function free() {
137 130
         if (is_resource($this->queryId)) {
138 131
             @mysqli_free_result($this->queryId);
139 132
         }
@@ -151,8 +144,7 @@  discard block
 block discarded – undo
151 144
     * @param string $file optionally pass __FILE__ calling the query for logging
152 145
     * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
153 146
     */
154
-    public function queryReturn($query, $line = '', $file = '')
155
-    {
147
+    public function queryReturn($query, $line = '', $file = '') {
156 148
         $this->query($query, $line, $file);
157 149
         if ($this->num_rows() == 0) {
158 150
             return false;
@@ -178,8 +170,7 @@  discard block
 block discarded – undo
178 170
     * @param string $file optionally pass __FILE__ calling the query for logging
179 171
     * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
180 172
     */
181
-    public function qr($query, $line = '', $file = '')
182
-    {
173
+    public function qr($query, $line = '', $file = '') {
183 174
         return $this->queryReturn($query, $line, $file);
184 175
     }
185 176
 
@@ -191,8 +182,7 @@  discard block
 block discarded – undo
191 182
     * @param string $line
192 183
     * @param string $file
193 184
     */
194
-    public function prepare($query, $line = '', $file = '')
195
-    {
185
+    public function prepare($query, $line = '', $file = '') {
196 186
         if (!$this->connect()) {
197 187
             return 0;
198 188
         }
@@ -252,8 +242,7 @@  discard block
 block discarded – undo
252 242
     * @param bool $log
253 243
     * @return mixed 0 if no query or query id handler, safe to ignore this return
254 244
     */
255
-    public function query($queryString, $line = '', $file = '', $log = false)
256
-    {
245
+    public function query($queryString, $line = '', $file = '', $log = false) {
257 246
         /* No empty queries, please, since PHP4 chokes on them. */
258 247
         /* The empty query string is passed on from the constructor,
259 248
         * when calling the class without a query, e.g. in situations
@@ -345,8 +334,7 @@  discard block
 block discarded – undo
345 334
     /**
346 335
     * @return array|null|object
347 336
     */
348
-    public function fetchObject()
349
-    {
337
+    public function fetchObject() {
350 338
         $this->Record = @mysqli_fetch_object($this->queryId);
351 339
         return $this->Record;
352 340
     }
@@ -359,8 +347,7 @@  discard block
 block discarded – undo
359 347
     * @param mixed $resultType
360 348
     * @return bool
361 349
     */
362
-    public function next_record($resultType = MYSQLI_BOTH)
363
-    {
350
+    public function next_record($resultType = MYSQLI_BOTH) {
364 351
         if ($this->queryId === false) {
365 352
             $this->haltmsg('next_record called with no query pending.');
366 353
             return 0;
@@ -384,8 +371,7 @@  discard block
 block discarded – undo
384 371
     * @param integer $pos the row numbe starting at 0 to switch to
385 372
     * @return bool whetherit was successfu or not.
386 373
     */
387
-    public function seek($pos = 0)
388
-    {
374
+    public function seek($pos = 0) {
389 375
         $status = @mysqli_data_seek($this->queryId, $pos);
390 376
         if ($status) {
391 377
             $this->Row = $pos;
@@ -405,8 +391,7 @@  discard block
 block discarded – undo
405 391
     *
406 392
     * @return bool
407 393
     */
408
-    public function transactionBegin()
409
-    {
394
+    public function transactionBegin() {
410 395
         if (version_compare(PHP_VERSION, '5.5.0') < 0) {
411 396
             return true;
412 397
         }
@@ -421,8 +406,7 @@  discard block
 block discarded – undo
421 406
     *
422 407
     * @return bool
423 408
     */
424
-    public function transactionCommit()
425
-    {
409
+    public function transactionCommit() {
426 410
         if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0) {
427 411
             return true;
428 412
         }
@@ -434,8 +418,7 @@  discard block
 block discarded – undo
434 418
     *
435 419
     * @return bool
436 420
     */
437
-    public function transactionAbort()
438
-    {
421
+    public function transactionAbort() {
439 422
         if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0) {
440 423
             return true;
441 424
         }
@@ -451,8 +434,7 @@  discard block
 block discarded – undo
451 434
     * @param string $field
452 435
     * @return int|string
453 436
     */
454
-    public function getLastInsertId($table, $field)
455
-    {
437
+    public function getLastInsertId($table, $field) {
456 438
         if (!isset($table) || $table == '' || !isset($field) || $field == '') {
457 439
             return -1;
458 440
         }
@@ -468,8 +450,7 @@  discard block
 block discarded – undo
468 450
     * @param string $mode
469 451
     * @return bool|int|\mysqli_result
470 452
     */
471
-    public function lock($table, $mode = 'write')
472
-    {
453
+    public function lock($table, $mode = 'write') {
473 454
         $this->connect();
474 455
         $query = 'lock tables ';
475 456
         if (is_array($table)) {
@@ -497,8 +478,7 @@  discard block
 block discarded – undo
497 478
     * @param bool $haltOnError optional, defaults to TRUE, whether or not to halt on error
498 479
     * @return bool|int|\mysqli_result
499 480
     */
500
-    public function unlock($haltOnError = true)
501
-    {
481
+    public function unlock($haltOnError = true) {
502 482
         $this->connect();
503 483
 
504 484
         $res = @mysqli_query($this->linkId, 'unlock tables');
@@ -515,8 +495,7 @@  discard block
 block discarded – undo
515 495
     * Db::affectedRows()
516 496
     * @return int
517 497
     */
518
-    public function affectedRows()
519
-    {
498
+    public function affectedRows() {
520 499
         return @mysqli_affected_rows($this->linkId);
521 500
     }
522 501
 
@@ -524,8 +503,7 @@  discard block
 block discarded – undo
524 503
     * Db::num_rows()
525 504
     * @return int
526 505
     */
527
-    public function num_rows()
528
-    {
506
+    public function num_rows() {
529 507
         return @mysqli_num_rows($this->queryId);
530 508
     }
531 509
 
@@ -533,8 +511,7 @@  discard block
 block discarded – undo
533 511
     * Db::num_fields()
534 512
     * @return int
535 513
     */
536
-    public function num_fields()
537
-    {
514
+    public function num_fields() {
538 515
         return @mysqli_num_fields($this->queryId);
539 516
     }
540 517
 
@@ -543,8 +520,7 @@  discard block
 block discarded – undo
543 520
     *
544 521
     * @return array
545 522
     */
546
-    public function tableNames()
547
-    {
523
+    public function tableNames() {
548 524
         $return = [];
549 525
         $this->query('SHOW TABLES');
550 526
         $i = 0;
Please login to merge, or discard this patch.
Indentation   +536 added lines, -536 removed lines patch added patch discarded remove patch
@@ -19,545 +19,545 @@
 block discarded – undo
19 19
 */
20 20
 class Db extends Generic implements Db_Interface
21 21
 {
22
-    /**
23
-    * @var string
24
-    */
25
-    public $type = 'mysqli';
26
-    public $statement;
27
-    public $statement_query;
28
-    public $statement_vars;
29
-
30
-    /**
31
-    * alias function of select_db, changes the database we are working with.
32
-    *
33
-    * @param string $database the name of the database to use
34
-    * @return void
35
-    */
36
-    public function useDb($database)
37
-    {
38
-        $this->selectDb($database);
39
-    }
40
-
41
-    /**
42
-    * changes the database we are working with.
43
-    *
44
-    * @param string $database the name of the database to use
45
-    * @return void
46
-    */
47
-    public function selectDb($database)
48
-    {
49
-        $this->connect();
50
-        mysqli_select_db($this->linkId, $database);
51
-    }
52
-
53
-    /* public: connection management */
54
-
55
-    /**
56
-    * Db::connect()
57
-    * @param string $database
58
-    * @param string $host
59
-    * @param string $user
60
-    * @param string $password
61
-    * @return int|\mysqli
62
-    */
63
-    public function connect($database = '', $host = '', $user = '', $password = '', $port = '')
64
-    {
65
-        /* Handle defaults */
66
-        if ($database == '') {
67
-            $database = $this->database;
68
-        }
69
-        if ($host == '') {
70
-            $host = $this->host;
71
-        }
72
-        if ($user == '') {
73
-            $user = $this->user;
74
-        }
75
-        if ($password == '') {
76
-            $password = $this->password;
77
-        }
78
-        if ($port == '') {
79
-            $port = $this->port;
80
-        }
81
-        /* establish connection, select database */
82
-        if (!is_object($this->linkId)) {
83
-            $this->connectionAttempt++;
84
-            if ($this->connectionAttempt >= $this->maxConnectErrors - 1) {
85
-                error_log("MySQLi Connection Attempt #{$this->connectionAttempt}/{$this->maxConnectErrors}");
86
-                exit;
87
-            }
88
-            if ($this->connectionAttempt >= $this->maxConnectErrors) {
89
-                $this->halt("connect($host, $user, \$password) failed. ".(is_object($this->linkId) && isset( $this->linkId->connect_error) ? $this->linkId->connect_error : ''));
90
-                return 0;
91
-            }
92
-            //error_log("real_connect($host, $user, $password, $database, $port)");
93
-            $this->linkId = mysqli_init();
94
-            $this->linkId->options(MYSQLI_INIT_COMMAND, "SET NAMES {$this->characterSet} COLLATE {$this->collation}, COLLATION_CONNECTION = {$this->collation}, COLLATION_DATABASE = {$this->collation}");
95
-            if (!$this->linkId->real_connect($host, $user, $password, $database, $port != '' ? $port : NULL)) {
96
-                $this->halt("connect($host, $user, \$password) failed. ".(is_object($this->linkId) && isset( $this->linkId->connect_error) ? $this->linkId->connect_error : ''));
97
-                return 0;
98
-            }
99
-            $this->linkId->set_charset($this->characterSet);
100
-            if ($this->linkId->connect_errno) {
101
-                $this->halt("connect($host, $user, \$password) failed. ".(is_object($this->linkId) && isset( $this->linkId->connect_error) ? $this->linkId->connect_error : ''));
102
-                return 0;
103
-            }
104
-        }
105
-        return $this->linkId;
106
-    }
107
-
108
-    /**
109
-    * Db::disconnect()
110
-    * @return bool
111
-    */
112
-    public function disconnect()
113
-    {
114
-        $return = !is_int($this->linkId) && method_exists($this->linkId, 'close') ? $this->linkId->close() : false;
115
-        $this->linkId = 0;
116
-        return $return;
117
-    }
118
-
119
-    /**
120
-    * @param $string
121
-    * @return string
122
-    */
123
-    public function real_escape($string = '')
124
-    {
125
-        if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect()) {
126
-            return $this->escape($string);
127
-        }
128
-        return mysqli_real_escape_string($this->linkId, $string);
129
-    }
130
-
131
-    /**
132
-    * discard the query result
133
-    * @return void
134
-    */
135
-    public function free()
136
-    {
137
-        if (is_resource($this->queryId)) {
138
-            @mysqli_free_result($this->queryId);
139
-        }
140
-        $this->queryId = 0;
141
-    }
142
-
143
-    /**
144
-    * Db::queryReturn()
145
-    *
146
-    * Sends an SQL query to the server like the normal query() command but iterates through
147
-    * any rows and returns the row or rows immediately or FALSE on error
148
-    *
149
-    * @param mixed $query SQL Query to be used
150
-    * @param string $line optionally pass __LINE__ calling the query for logging
151
-    * @param string $file optionally pass __FILE__ calling the query for logging
152
-    * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
153
-    */
154
-    public function queryReturn($query, $line = '', $file = '')
155
-    {
156
-        $this->query($query, $line, $file);
157
-        if ($this->num_rows() == 0) {
158
-            return false;
159
-        } elseif ($this->num_rows() == 1) {
160
-            $this->next_record(MYSQLI_ASSOC);
161
-            return $this->Record;
162
-        } else {
163
-            $out = [];
164
-            while ($this->next_record(MYSQLI_ASSOC)) {
165
-                $out[] = $this->Record;
166
-            }
167
-            return $out;
168
-        }
169
-    }
170
-
171
-    /**
172
-    * db:qr()
173
-    *
174
-    *  alias of queryReturn()
175
-    *
176
-    * @param mixed $query SQL Query to be used
177
-    * @param string $line optionally pass __LINE__ calling the query for logging
178
-    * @param string $file optionally pass __FILE__ calling the query for logging
179
-    * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
180
-    */
181
-    public function qr($query, $line = '', $file = '')
182
-    {
183
-        return $this->queryReturn($query, $line, $file);
184
-    }
185
-
186
-    /**
187
-    * creates a prepaired statement from query
188
-    *
189
-    * @param string $query sql query like INSERT INTO table (col) VALUES (?)  or  SELECT * from table WHERE col1 = ? and col2 = ?  or  UPDATE table SET col1 = ?, col2 = ? WHERE col3 = ?
190
-    * @return false|mysqli_stmt
191
-    * @param string $line
192
-    * @param string $file
193
-    */
194
-    public function prepare($query, $line = '', $file = '')
195
-    {
196
-        if (!$this->connect()) {
197
-            return 0;
198
-        }
199
-        $haltPrev = $this->haltOnError;
200
-        $this->haltOnError = 'no';
201
-        $start = microtime(true);
202
-        $this->statement = mysqli_prepare($this->linkId, $query);
203
-        if (!isset($GLOBALS['disable_db_queries'])) {
204
-            $this->statement_query = $query;
205
-            $this->addLog($query, microtime(true) - $start, $line, $file);
206
-        }
207
-        return $this->statement;
208
-    }
209
-
210
-    /**
211
-    * Binds variables to a prepared statement as parameters
212
-    * 
213
-    * @param string $types A string that contains one or more characters which specify the types for the corresponding bind variables: (i)nt, (d)ecimal, (s)tring, (b)inary 
214
-    * @param mixed $vars
215
-    * @return bool indicates success
216
-    */
217
-    public function bind_param($types, &...$vars) {
218
-        $params = [$this->statement, $types];
219
-        foreach ($vars as &$var) {
220
-            $params[] = &$var; // Ensure they stay references
221
-        }
222
-        if (!isset($GLOBALS['disable_db_queries'])) {
223
-            $this->statement_vars &= $vars;
224
-        }
225
-        return call_user_func_array('mysqli_stmt_bind_param', $params);
226
-    }
227
-
228
-    /**
229
-    * Executes a prepared statement
230
-    * 
231
-    * @return bool success
232
-    */
233
-    public function execute($line = '', $file = '') {
234
-        $start = microtime(true);
235
-        $return = mysqli_stmt_execute($this->statement);
236
-        if (!isset($GLOBALS['disable_db_queries'])) {
237
-            $vars = $this->statement_vars;
238
-            $query = $result = preg_replace_callback('/\?/', function () use (&$vars) {
239
-                return array_shift($vars);
240
-                }, $this->statement_query);
241
-            $this->addLog($query, microtime(true) - $start, $line, $file);
242
-        }
243
-        return $return;
244
-    }
245
-
246
-    /**
247
-    * Db::query()
248
-    *
249
-    *  Sends an SQL query to the database
250
-    *
251
-    * @param mixed $queryString
252
-    * @param int $line
253
-    * @param string $file
254
-    * @param bool $log
255
-    * @return mixed 0 if no query or query id handler, safe to ignore this return
256
-    */
257
-    public function query($queryString, $line = '', $file = '', $log = false)
258
-    {
259
-        /* No empty queries, please, since PHP4 chokes on them. */
260
-        /* The empty query string is passed on from the constructor,
22
+	/**
23
+	 * @var string
24
+	 */
25
+	public $type = 'mysqli';
26
+	public $statement;
27
+	public $statement_query;
28
+	public $statement_vars;
29
+
30
+	/**
31
+	 * alias function of select_db, changes the database we are working with.
32
+	 *
33
+	 * @param string $database the name of the database to use
34
+	 * @return void
35
+	 */
36
+	public function useDb($database)
37
+	{
38
+		$this->selectDb($database);
39
+	}
40
+
41
+	/**
42
+	 * changes the database we are working with.
43
+	 *
44
+	 * @param string $database the name of the database to use
45
+	 * @return void
46
+	 */
47
+	public function selectDb($database)
48
+	{
49
+		$this->connect();
50
+		mysqli_select_db($this->linkId, $database);
51
+	}
52
+
53
+	/* public: connection management */
54
+
55
+	/**
56
+	 * Db::connect()
57
+	 * @param string $database
58
+	 * @param string $host
59
+	 * @param string $user
60
+	 * @param string $password
61
+	 * @return int|\mysqli
62
+	 */
63
+	public function connect($database = '', $host = '', $user = '', $password = '', $port = '')
64
+	{
65
+		/* Handle defaults */
66
+		if ($database == '') {
67
+			$database = $this->database;
68
+		}
69
+		if ($host == '') {
70
+			$host = $this->host;
71
+		}
72
+		if ($user == '') {
73
+			$user = $this->user;
74
+		}
75
+		if ($password == '') {
76
+			$password = $this->password;
77
+		}
78
+		if ($port == '') {
79
+			$port = $this->port;
80
+		}
81
+		/* establish connection, select database */
82
+		if (!is_object($this->linkId)) {
83
+			$this->connectionAttempt++;
84
+			if ($this->connectionAttempt >= $this->maxConnectErrors - 1) {
85
+				error_log("MySQLi Connection Attempt #{$this->connectionAttempt}/{$this->maxConnectErrors}");
86
+				exit;
87
+			}
88
+			if ($this->connectionAttempt >= $this->maxConnectErrors) {
89
+				$this->halt("connect($host, $user, \$password) failed. ".(is_object($this->linkId) && isset( $this->linkId->connect_error) ? $this->linkId->connect_error : ''));
90
+				return 0;
91
+			}
92
+			//error_log("real_connect($host, $user, $password, $database, $port)");
93
+			$this->linkId = mysqli_init();
94
+			$this->linkId->options(MYSQLI_INIT_COMMAND, "SET NAMES {$this->characterSet} COLLATE {$this->collation}, COLLATION_CONNECTION = {$this->collation}, COLLATION_DATABASE = {$this->collation}");
95
+			if (!$this->linkId->real_connect($host, $user, $password, $database, $port != '' ? $port : NULL)) {
96
+				$this->halt("connect($host, $user, \$password) failed. ".(is_object($this->linkId) && isset( $this->linkId->connect_error) ? $this->linkId->connect_error : ''));
97
+				return 0;
98
+			}
99
+			$this->linkId->set_charset($this->characterSet);
100
+			if ($this->linkId->connect_errno) {
101
+				$this->halt("connect($host, $user, \$password) failed. ".(is_object($this->linkId) && isset( $this->linkId->connect_error) ? $this->linkId->connect_error : ''));
102
+				return 0;
103
+			}
104
+		}
105
+		return $this->linkId;
106
+	}
107
+
108
+	/**
109
+	 * Db::disconnect()
110
+	 * @return bool
111
+	 */
112
+	public function disconnect()
113
+	{
114
+		$return = !is_int($this->linkId) && method_exists($this->linkId, 'close') ? $this->linkId->close() : false;
115
+		$this->linkId = 0;
116
+		return $return;
117
+	}
118
+
119
+	/**
120
+	 * @param $string
121
+	 * @return string
122
+	 */
123
+	public function real_escape($string = '')
124
+	{
125
+		if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect()) {
126
+			return $this->escape($string);
127
+		}
128
+		return mysqli_real_escape_string($this->linkId, $string);
129
+	}
130
+
131
+	/**
132
+	 * discard the query result
133
+	 * @return void
134
+	 */
135
+	public function free()
136
+	{
137
+		if (is_resource($this->queryId)) {
138
+			@mysqli_free_result($this->queryId);
139
+		}
140
+		$this->queryId = 0;
141
+	}
142
+
143
+	/**
144
+	 * Db::queryReturn()
145
+	 *
146
+	 * Sends an SQL query to the server like the normal query() command but iterates through
147
+	 * any rows and returns the row or rows immediately or FALSE on error
148
+	 *
149
+	 * @param mixed $query SQL Query to be used
150
+	 * @param string $line optionally pass __LINE__ calling the query for logging
151
+	 * @param string $file optionally pass __FILE__ calling the query for logging
152
+	 * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
153
+	 */
154
+	public function queryReturn($query, $line = '', $file = '')
155
+	{
156
+		$this->query($query, $line, $file);
157
+		if ($this->num_rows() == 0) {
158
+			return false;
159
+		} elseif ($this->num_rows() == 1) {
160
+			$this->next_record(MYSQLI_ASSOC);
161
+			return $this->Record;
162
+		} else {
163
+			$out = [];
164
+			while ($this->next_record(MYSQLI_ASSOC)) {
165
+				$out[] = $this->Record;
166
+			}
167
+			return $out;
168
+		}
169
+	}
170
+
171
+	/**
172
+	 * db:qr()
173
+	 *
174
+	 *  alias of queryReturn()
175
+	 *
176
+	 * @param mixed $query SQL Query to be used
177
+	 * @param string $line optionally pass __LINE__ calling the query for logging
178
+	 * @param string $file optionally pass __FILE__ calling the query for logging
179
+	 * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
180
+	 */
181
+	public function qr($query, $line = '', $file = '')
182
+	{
183
+		return $this->queryReturn($query, $line, $file);
184
+	}
185
+
186
+	/**
187
+	 * creates a prepaired statement from query
188
+	 *
189
+	 * @param string $query sql query like INSERT INTO table (col) VALUES (?)  or  SELECT * from table WHERE col1 = ? and col2 = ?  or  UPDATE table SET col1 = ?, col2 = ? WHERE col3 = ?
190
+	 * @return false|mysqli_stmt
191
+	 * @param string $line
192
+	 * @param string $file
193
+	 */
194
+	public function prepare($query, $line = '', $file = '')
195
+	{
196
+		if (!$this->connect()) {
197
+			return 0;
198
+		}
199
+		$haltPrev = $this->haltOnError;
200
+		$this->haltOnError = 'no';
201
+		$start = microtime(true);
202
+		$this->statement = mysqli_prepare($this->linkId, $query);
203
+		if (!isset($GLOBALS['disable_db_queries'])) {
204
+			$this->statement_query = $query;
205
+			$this->addLog($query, microtime(true) - $start, $line, $file);
206
+		}
207
+		return $this->statement;
208
+	}
209
+
210
+	/**
211
+	 * Binds variables to a prepared statement as parameters
212
+	 * 
213
+	 * @param string $types A string that contains one or more characters which specify the types for the corresponding bind variables: (i)nt, (d)ecimal, (s)tring, (b)inary 
214
+	 * @param mixed $vars
215
+	 * @return bool indicates success
216
+	 */
217
+	public function bind_param($types, &...$vars) {
218
+		$params = [$this->statement, $types];
219
+		foreach ($vars as &$var) {
220
+			$params[] = &$var; // Ensure they stay references
221
+		}
222
+		if (!isset($GLOBALS['disable_db_queries'])) {
223
+			$this->statement_vars &= $vars;
224
+		}
225
+		return call_user_func_array('mysqli_stmt_bind_param', $params);
226
+	}
227
+
228
+	/**
229
+	 * Executes a prepared statement
230
+	 * 
231
+	 * @return bool success
232
+	 */
233
+	public function execute($line = '', $file = '') {
234
+		$start = microtime(true);
235
+		$return = mysqli_stmt_execute($this->statement);
236
+		if (!isset($GLOBALS['disable_db_queries'])) {
237
+			$vars = $this->statement_vars;
238
+			$query = $result = preg_replace_callback('/\?/', function () use (&$vars) {
239
+				return array_shift($vars);
240
+				}, $this->statement_query);
241
+			$this->addLog($query, microtime(true) - $start, $line, $file);
242
+		}
243
+		return $return;
244
+	}
245
+
246
+	/**
247
+	 * Db::query()
248
+	 *
249
+	 *  Sends an SQL query to the database
250
+	 *
251
+	 * @param mixed $queryString
252
+	 * @param int $line
253
+	 * @param string $file
254
+	 * @param bool $log
255
+	 * @return mixed 0 if no query or query id handler, safe to ignore this return
256
+	 */
257
+	public function query($queryString, $line = '', $file = '', $log = false)
258
+	{
259
+		/* No empty queries, please, since PHP4 chokes on them. */
260
+		/* The empty query string is passed on from the constructor,
261 261
         * when calling the class without a query, e.g. in situations
262 262
         * like these: '$db = new db_Subclass;'
263 263
         */
264
-        if ($queryString == '') {
265
-            return 0;
266
-        }
267
-        if (!$this->connect()) {
268
-            return 0;
269
-            /* we already complained in connect() about that. */
270
-        }
271
-        $haltPrev = $this->haltOnError;
272
-        $this->haltOnError = 'no';
273
-        // New query, discard previous result.
274
-        if (is_resource($this->queryId)) {
275
-            $this->free();
276
-        }
277
-        if ($this->Debug) {
278
-            printf("Debug: query = %s<br>\n", $queryString);
279
-        }
280
-        if ($log === true || (isset($GLOBALS['log_queries']) && $GLOBALS['log_queries'] !== false)) {
281
-            $this->log($queryString, $line, $file);
282
-        }
283
-        $tries = 2;
284
-        $try = 0;
285
-        $this->queryId = false;
286
-        while ((null === $this->queryId || $this->queryId === false) && $try <= $tries) {
287
-            $try++;
288
-            if ($try > 1) {
289
-                @mysqli_close($this->linkId);
290
-                $this->linkId = 0;
291
-            }
292
-            $start = microtime(true);
293
-            $onlyRollback = true;
294
-            $fails = -1;
295
-            while ($fails < 30 && (null === $this->queryId || $this->queryId === false)) {
296
-                $this->connect();
297
-                $fails++;
298
-                try {
299
-                    $this->queryId = @mysqli_query($this->linkId, $queryString, MYSQLI_STORE_RESULT);
300
-                    if (in_array((int)@mysqli_errno($this->linkId), [1213, 2006, 3101, 1180])) {
301
-                        //error_log("got ".@mysqli_errno($this->linkId)." sql error fails {$fails} on query {$queryString} from {$line}:{$file}");
302
-                        usleep(250000); // 0.25 second
303
-                    } else {
304
-                        $onlyRollback = false;
305
-                        if (in_array((int)@mysqli_errno($this->linkId), [1064])) {
306
-                            $tries = 0;
307
-                        }
308
-                        break;
309
-                    }
310
-                } catch (\mysqli_sql_exception $e) {
311
-                    if (in_array((int)$e->getCode(), [1213, 2006, 3101, 1180])) {
312
-                        //error_log("got ".$e->getCode()." sql error fails {$fails}");
313
-                        usleep(250000); // 0.25 second
314
-                    } else {
315
-                        error_log('Got mysqli_sql_exception code '.$e->getCode().' error '.$e->getMessage().' on query '.$queryString.' from '.$line.':'.$file);
316
-                        $onlyRollback = false;
317
-                        if (in_array((int)@mysqli_errno($this->linkId), [1064])) {
318
-                            $tries = 0;
319
-                        }
320
-                        break;
321
-                    }
322
-                }
323
-            }
324
-            if (!isset($GLOBALS['disable_db_queries'])) {
325
-                $this->addLog($queryString, microtime(true) - $start, $line, $file);
326
-            }
327
-            $this->Row = 0;
328
-            $this->Errno = @mysqli_errno($this->linkId);
329
-            $this->Error = @mysqli_error($this->linkId);
330
-            if ($try == 1 && (null === $this->queryId || $this->queryId === false)) {
331
-                //$this->emailError($queryString, 'Error #'.$this->Errno.': '.$this->Error, $line, $file);
332
-            }
333
-        }
334
-        $this->haltOnError = $haltPrev;
335
-        if ($onlyRollback === true && false === $this->queryId) {
336
-            error_log('Got MySQLi 3101 Rollback Error '.$fails.' Times, Giving Up on '.$queryString.' from '.$line.':'.$file.' on '.__LINE__.':'.__FILE__);
337
-        }
338
-        if (null === $this->queryId || $this->queryId === false) {
339
-            $this->emailError($queryString, 'Error #'.$this->Errno.': '.$this->Error, $line, $file);
340
-            $this->halt('', $line, $file);
341
-        }
342
-
343
-        // Will return nada if it fails. That's fine.
344
-        return $this->queryId;
345
-    }
346
-
347
-    /**
348
-    * @return array|null|object
349
-    */
350
-    public function fetchObject()
351
-    {
352
-        $this->Record = @mysqli_fetch_object($this->queryId);
353
-        return $this->Record;
354
-    }
355
-
356
-    /* public: walk result set */
357
-
358
-    /**
359
-    * Db::next_record()
360
-    *
361
-    * @param mixed $resultType
362
-    * @return bool
363
-    */
364
-    public function next_record($resultType = MYSQLI_BOTH)
365
-    {
366
-        if ($this->queryId === false) {
367
-            $this->haltmsg('next_record called with no query pending.');
368
-            return 0;
369
-        }
370
-
371
-        $this->Record = @mysqli_fetch_array($this->queryId, $resultType);
372
-        ++$this->Row;
373
-        $this->Errno = mysqli_errno($this->linkId);
374
-        $this->Error = mysqli_error($this->linkId);
375
-
376
-        $stat = is_array($this->Record);
377
-        if (!$stat && $this->autoFree && is_resource($this->queryId)) {
378
-            $this->free();
379
-        }
380
-        return $stat;
381
-    }
382
-
383
-    /**
384
-    * switch to position in result set
385
-    *
386
-    * @param integer $pos the row numbe starting at 0 to switch to
387
-    * @return bool whetherit was successfu or not.
388
-    */
389
-    public function seek($pos = 0)
390
-    {
391
-        $status = @mysqli_data_seek($this->queryId, $pos);
392
-        if ($status) {
393
-            $this->Row = $pos;
394
-        } else {
395
-            $this->haltmsg("seek({$pos}) failed: result has ".$this->num_rows().' rows', __LINE__, __FILE__);
396
-            /* half assed attempt to save the day, but do not consider this documented or even desirable behaviour. */
397
-            $rows = $this->num_rows();
398
-            @mysqli_data_seek($this->queryId, $rows);
399
-            $this->Row = $rows;
400
-            return false;
401
-        }
402
-        return true;
403
-    }
404
-
405
-    /**
406
-    * Initiates a transaction
407
-    *
408
-    * @return bool
409
-    */
410
-    public function transactionBegin()
411
-    {
412
-        if (version_compare(PHP_VERSION, '5.5.0') < 0) {
413
-            return true;
414
-        }
415
-        if (!$this->connect()) {
416
-            return 0;
417
-        }
418
-        return mysqli_begin_transaction($this->linkId);
419
-    }
420
-
421
-    /**
422
-    * Commits a transaction
423
-    *
424
-    * @return bool
425
-    */
426
-    public function transactionCommit()
427
-    {
428
-        if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0) {
429
-            return true;
430
-        }
431
-        return mysqli_commit($this->linkId);
432
-    }
433
-
434
-    /**
435
-    * Rolls back a transaction
436
-    *
437
-    * @return bool
438
-    */
439
-    public function transactionAbort()
440
-    {
441
-        if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0) {
442
-            return true;
443
-        }
444
-        return mysqli_rollback($this->linkId);
445
-    }
446
-
447
-    /**
448
-    * This will get the last insert ID created on the current connection.  Should only be called after an insert query is
449
-    * run on a table that has an auto incrementing field.  $table and $field are required, but unused here since it's
450
-    * unnecessary for mysql.  For compatibility with pgsql, the params must be supplied.
451
-    *
452
-    * @param string $table
453
-    * @param string $field
454
-    * @return int|string
455
-    */
456
-    public function getLastInsertId($table, $field)
457
-    {
458
-        if (!isset($table) || $table == '' || !isset($field) || $field == '') {
459
-            return -1;
460
-        }
461
-
462
-        return @mysqli_insert_id($this->linkId);
463
-    }
464
-
465
-    /* public: table locking */
466
-
467
-    /**
468
-    * Db::lock()
469
-    * @param mixed  $table
470
-    * @param string $mode
471
-    * @return bool|int|\mysqli_result
472
-    */
473
-    public function lock($table, $mode = 'write')
474
-    {
475
-        $this->connect();
476
-        $query = 'lock tables ';
477
-        if (is_array($table)) {
478
-            foreach ($table as $key => $value) {
479
-                if ($key == 'read' && $key != 0) {
480
-                    $query .= "$value read, ";
481
-                } else {
482
-                    $query .= "$value $mode, ";
483
-                }
484
-            }
485
-            $query = mb_substr($query, 0, -2);
486
-        } else {
487
-            $query .= "$table $mode";
488
-        }
489
-        $res = @mysqli_query($this->linkId, $query);
490
-        if (!$res) {
491
-            $this->halt("lock($table, $mode) failed.");
492
-            return 0;
493
-        }
494
-        return $res;
495
-    }
496
-
497
-    /**
498
-    * Db::unlock()
499
-    * @param bool $haltOnError optional, defaults to TRUE, whether or not to halt on error
500
-    * @return bool|int|\mysqli_result
501
-    */
502
-    public function unlock($haltOnError = true)
503
-    {
504
-        $this->connect();
505
-
506
-        $res = @mysqli_query($this->linkId, 'unlock tables');
507
-        if ($haltOnError === true && !$res) {
508
-            $this->halt('unlock() failed.');
509
-            return 0;
510
-        }
511
-        return $res;
512
-    }
513
-
514
-    /* public: evaluate the result (size, width) */
515
-
516
-    /**
517
-    * Db::affectedRows()
518
-    * @return int
519
-    */
520
-    public function affectedRows()
521
-    {
522
-        return @mysqli_affected_rows($this->linkId);
523
-    }
524
-
525
-    /**
526
-    * Db::num_rows()
527
-    * @return int
528
-    */
529
-    public function num_rows()
530
-    {
531
-        return @mysqli_num_rows($this->queryId);
532
-    }
533
-
534
-    /**
535
-    * Db::num_fields()
536
-    * @return int
537
-    */
538
-    public function num_fields()
539
-    {
540
-        return @mysqli_num_fields($this->queryId);
541
-    }
542
-
543
-    /**
544
-    * gets an array of the table names in teh current datase
545
-    *
546
-    * @return array
547
-    */
548
-    public function tableNames()
549
-    {
550
-        $return = [];
551
-        $this->query('SHOW TABLES');
552
-        $i = 0;
553
-        while ($info = $this->queryId->fetch_row()) {
554
-            $return[$i]['table_name'] = $info[0];
555
-            $return[$i]['tablespace_name'] = $this->database;
556
-            $return[$i]['database'] = $this->database;
557
-            ++$i;
558
-        }
559
-        return $return;
560
-    }
264
+		if ($queryString == '') {
265
+			return 0;
266
+		}
267
+		if (!$this->connect()) {
268
+			return 0;
269
+			/* we already complained in connect() about that. */
270
+		}
271
+		$haltPrev = $this->haltOnError;
272
+		$this->haltOnError = 'no';
273
+		// New query, discard previous result.
274
+		if (is_resource($this->queryId)) {
275
+			$this->free();
276
+		}
277
+		if ($this->Debug) {
278
+			printf("Debug: query = %s<br>\n", $queryString);
279
+		}
280
+		if ($log === true || (isset($GLOBALS['log_queries']) && $GLOBALS['log_queries'] !== false)) {
281
+			$this->log($queryString, $line, $file);
282
+		}
283
+		$tries = 2;
284
+		$try = 0;
285
+		$this->queryId = false;
286
+		while ((null === $this->queryId || $this->queryId === false) && $try <= $tries) {
287
+			$try++;
288
+			if ($try > 1) {
289
+				@mysqli_close($this->linkId);
290
+				$this->linkId = 0;
291
+			}
292
+			$start = microtime(true);
293
+			$onlyRollback = true;
294
+			$fails = -1;
295
+			while ($fails < 30 && (null === $this->queryId || $this->queryId === false)) {
296
+				$this->connect();
297
+				$fails++;
298
+				try {
299
+					$this->queryId = @mysqli_query($this->linkId, $queryString, MYSQLI_STORE_RESULT);
300
+					if (in_array((int)@mysqli_errno($this->linkId), [1213, 2006, 3101, 1180])) {
301
+						//error_log("got ".@mysqli_errno($this->linkId)." sql error fails {$fails} on query {$queryString} from {$line}:{$file}");
302
+						usleep(250000); // 0.25 second
303
+					} else {
304
+						$onlyRollback = false;
305
+						if (in_array((int)@mysqli_errno($this->linkId), [1064])) {
306
+							$tries = 0;
307
+						}
308
+						break;
309
+					}
310
+				} catch (\mysqli_sql_exception $e) {
311
+					if (in_array((int)$e->getCode(), [1213, 2006, 3101, 1180])) {
312
+						//error_log("got ".$e->getCode()." sql error fails {$fails}");
313
+						usleep(250000); // 0.25 second
314
+					} else {
315
+						error_log('Got mysqli_sql_exception code '.$e->getCode().' error '.$e->getMessage().' on query '.$queryString.' from '.$line.':'.$file);
316
+						$onlyRollback = false;
317
+						if (in_array((int)@mysqli_errno($this->linkId), [1064])) {
318
+							$tries = 0;
319
+						}
320
+						break;
321
+					}
322
+				}
323
+			}
324
+			if (!isset($GLOBALS['disable_db_queries'])) {
325
+				$this->addLog($queryString, microtime(true) - $start, $line, $file);
326
+			}
327
+			$this->Row = 0;
328
+			$this->Errno = @mysqli_errno($this->linkId);
329
+			$this->Error = @mysqli_error($this->linkId);
330
+			if ($try == 1 && (null === $this->queryId || $this->queryId === false)) {
331
+				//$this->emailError($queryString, 'Error #'.$this->Errno.': '.$this->Error, $line, $file);
332
+			}
333
+		}
334
+		$this->haltOnError = $haltPrev;
335
+		if ($onlyRollback === true && false === $this->queryId) {
336
+			error_log('Got MySQLi 3101 Rollback Error '.$fails.' Times, Giving Up on '.$queryString.' from '.$line.':'.$file.' on '.__LINE__.':'.__FILE__);
337
+		}
338
+		if (null === $this->queryId || $this->queryId === false) {
339
+			$this->emailError($queryString, 'Error #'.$this->Errno.': '.$this->Error, $line, $file);
340
+			$this->halt('', $line, $file);
341
+		}
342
+
343
+		// Will return nada if it fails. That's fine.
344
+		return $this->queryId;
345
+	}
346
+
347
+	/**
348
+	 * @return array|null|object
349
+	 */
350
+	public function fetchObject()
351
+	{
352
+		$this->Record = @mysqli_fetch_object($this->queryId);
353
+		return $this->Record;
354
+	}
355
+
356
+	/* public: walk result set */
357
+
358
+	/**
359
+	 * Db::next_record()
360
+	 *
361
+	 * @param mixed $resultType
362
+	 * @return bool
363
+	 */
364
+	public function next_record($resultType = MYSQLI_BOTH)
365
+	{
366
+		if ($this->queryId === false) {
367
+			$this->haltmsg('next_record called with no query pending.');
368
+			return 0;
369
+		}
370
+
371
+		$this->Record = @mysqli_fetch_array($this->queryId, $resultType);
372
+		++$this->Row;
373
+		$this->Errno = mysqli_errno($this->linkId);
374
+		$this->Error = mysqli_error($this->linkId);
375
+
376
+		$stat = is_array($this->Record);
377
+		if (!$stat && $this->autoFree && is_resource($this->queryId)) {
378
+			$this->free();
379
+		}
380
+		return $stat;
381
+	}
382
+
383
+	/**
384
+	 * switch to position in result set
385
+	 *
386
+	 * @param integer $pos the row numbe starting at 0 to switch to
387
+	 * @return bool whetherit was successfu or not.
388
+	 */
389
+	public function seek($pos = 0)
390
+	{
391
+		$status = @mysqli_data_seek($this->queryId, $pos);
392
+		if ($status) {
393
+			$this->Row = $pos;
394
+		} else {
395
+			$this->haltmsg("seek({$pos}) failed: result has ".$this->num_rows().' rows', __LINE__, __FILE__);
396
+			/* half assed attempt to save the day, but do not consider this documented or even desirable behaviour. */
397
+			$rows = $this->num_rows();
398
+			@mysqli_data_seek($this->queryId, $rows);
399
+			$this->Row = $rows;
400
+			return false;
401
+		}
402
+		return true;
403
+	}
404
+
405
+	/**
406
+	 * Initiates a transaction
407
+	 *
408
+	 * @return bool
409
+	 */
410
+	public function transactionBegin()
411
+	{
412
+		if (version_compare(PHP_VERSION, '5.5.0') < 0) {
413
+			return true;
414
+		}
415
+		if (!$this->connect()) {
416
+			return 0;
417
+		}
418
+		return mysqli_begin_transaction($this->linkId);
419
+	}
420
+
421
+	/**
422
+	 * Commits a transaction
423
+	 *
424
+	 * @return bool
425
+	 */
426
+	public function transactionCommit()
427
+	{
428
+		if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0) {
429
+			return true;
430
+		}
431
+		return mysqli_commit($this->linkId);
432
+	}
433
+
434
+	/**
435
+	 * Rolls back a transaction
436
+	 *
437
+	 * @return bool
438
+	 */
439
+	public function transactionAbort()
440
+	{
441
+		if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0) {
442
+			return true;
443
+		}
444
+		return mysqli_rollback($this->linkId);
445
+	}
446
+
447
+	/**
448
+	 * This will get the last insert ID created on the current connection.  Should only be called after an insert query is
449
+	 * run on a table that has an auto incrementing field.  $table and $field are required, but unused here since it's
450
+	 * unnecessary for mysql.  For compatibility with pgsql, the params must be supplied.
451
+	 *
452
+	 * @param string $table
453
+	 * @param string $field
454
+	 * @return int|string
455
+	 */
456
+	public function getLastInsertId($table, $field)
457
+	{
458
+		if (!isset($table) || $table == '' || !isset($field) || $field == '') {
459
+			return -1;
460
+		}
461
+
462
+		return @mysqli_insert_id($this->linkId);
463
+	}
464
+
465
+	/* public: table locking */
466
+
467
+	/**
468
+	 * Db::lock()
469
+	 * @param mixed  $table
470
+	 * @param string $mode
471
+	 * @return bool|int|\mysqli_result
472
+	 */
473
+	public function lock($table, $mode = 'write')
474
+	{
475
+		$this->connect();
476
+		$query = 'lock tables ';
477
+		if (is_array($table)) {
478
+			foreach ($table as $key => $value) {
479
+				if ($key == 'read' && $key != 0) {
480
+					$query .= "$value read, ";
481
+				} else {
482
+					$query .= "$value $mode, ";
483
+				}
484
+			}
485
+			$query = mb_substr($query, 0, -2);
486
+		} else {
487
+			$query .= "$table $mode";
488
+		}
489
+		$res = @mysqli_query($this->linkId, $query);
490
+		if (!$res) {
491
+			$this->halt("lock($table, $mode) failed.");
492
+			return 0;
493
+		}
494
+		return $res;
495
+	}
496
+
497
+	/**
498
+	 * Db::unlock()
499
+	 * @param bool $haltOnError optional, defaults to TRUE, whether or not to halt on error
500
+	 * @return bool|int|\mysqli_result
501
+	 */
502
+	public function unlock($haltOnError = true)
503
+	{
504
+		$this->connect();
505
+
506
+		$res = @mysqli_query($this->linkId, 'unlock tables');
507
+		if ($haltOnError === true && !$res) {
508
+			$this->halt('unlock() failed.');
509
+			return 0;
510
+		}
511
+		return $res;
512
+	}
513
+
514
+	/* public: evaluate the result (size, width) */
515
+
516
+	/**
517
+	 * Db::affectedRows()
518
+	 * @return int
519
+	 */
520
+	public function affectedRows()
521
+	{
522
+		return @mysqli_affected_rows($this->linkId);
523
+	}
524
+
525
+	/**
526
+	 * Db::num_rows()
527
+	 * @return int
528
+	 */
529
+	public function num_rows()
530
+	{
531
+		return @mysqli_num_rows($this->queryId);
532
+	}
533
+
534
+	/**
535
+	 * Db::num_fields()
536
+	 * @return int
537
+	 */
538
+	public function num_fields()
539
+	{
540
+		return @mysqli_num_fields($this->queryId);
541
+	}
542
+
543
+	/**
544
+	 * gets an array of the table names in teh current datase
545
+	 *
546
+	 * @return array
547
+	 */
548
+	public function tableNames()
549
+	{
550
+		$return = [];
551
+		$this->query('SHOW TABLES');
552
+		$i = 0;
553
+		while ($info = $this->queryId->fetch_row()) {
554
+			$return[$i]['table_name'] = $info[0];
555
+			$return[$i]['tablespace_name'] = $this->database;
556
+			$return[$i]['database'] = $this->database;
557
+			++$i;
558
+		}
559
+		return $return;
560
+	}
561 561
 }
562 562
 
563 563
 /**
Please login to merge, or discard this patch.