Test Failed
Push — master ( 8b6eb2...d03f69 )
by Joe
17:14 queued 10:05
created
src/Pgsql/Db.php 1 patch
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.
src/Mdb2/Db.php 1 patch
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.
src/Db_Interface.php 1 patch
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.
src/Adodb/Db.php 1 patch
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.
src/Pdo/Db.php 1 patch
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.
src/Generic.php 1 patch
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.
src/Loader.php 1 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/Mysqli/Db.php 1 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.