Test Failed
Push — master ( e9c576...010f10 )
by Joe
03:45
created

Db::createDatabase()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 15
nc 2
nop 2
dl 0
loc 19
ccs 0
cts 16
cp 0
crap 6
rs 9.7666
c 0
b 0
f 0
1
<?php
2
/**
3
* MDB2 Wrapper Made To Handle Like Our Other Classes Related Functionality
4
* @author Joe Huss <[email protected]>
5
* @copyright 2018
6
* @package MyAdmin
7
* @category SQL
8
*/
9
10
namespace MyDb\Mdb2;
11
12
use \MyDb\Generic;
13
use \MyDb\Db_Interface;
14
15
/**
16
 * Db
17
 *
18
 * @access public
19
 */
20
class Db extends Generic implements Db_Interface {
21
	public $host = 'localhost';
22
	public $user = 'pdns';
23
	public $password = '';
24
	public $database = 'pdns';
25
	public $type = 'mdb2';
26
	public $error = false;
27
	public $message = '';
28
29
	/**
30
	 * Db::quote()
31
	 * @param string $text
32
	 * @param string $type
33
	 * @return string
34
	 */
35
	public function quote($text = '', $type = 'text') {
36
		switch ($type) {
37
			case 'text':
38
				return "'".mysqli_real_escape_string($this->linkId, $text)."'";
0 ignored issues
show
Bug introduced by
$this->linkId of type integer is incompatible with the type mysqli expected by parameter $link of mysqli_real_escape_string(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
				return "'".mysqli_real_escape_string(/** @scrutinizer ignore-type */ $this->linkId, $text)."'";
Loading history...
39
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
40
			case 'integer':
41
				return (int) $text;
42
				break;
43
			default:
44
				return $text;
45
				break;
46
		}
47
	}
48
49
	/**
50
	 * Db::queryOne()
51
	 *
52
	 * @param mixed $query
53
	 * @param string $line
54
	 * @param string $file
55
	 * @return bool
56
	 */
57
	public function queryOne($query, $line = '', $file = '') {
58
		$this->query($query, $line, $file);
59
		if ($this->num_rows() > 0) {
60
			$this->next_record();
61
			return $this->f(0);
62
		} else
63
			return 0;
64
	}
65
66
	/**
67
	 * Db::queryRow()
68
	 *
69
	 * @param mixed $query
70
	 * @param string $line
71
	 * @param string $file
72
	 * @return array|bool
73
	 */
74
	public function queryRow($query, $line = '', $file = '') {
75
		$this->query($query, $line, $file);
76
		if ($this->num_rows() > 0) {
77
			$this->next_record();
78
			return $this->Record;
79
		} else
80
			return 0;
81
	}
82
83
	/**
84
	 * Db::lastInsertId()
85
	 * @param mixed $table
86
	 * @param mixed $field
87
	 * @return int
88
	 */
89
	public function lastInsertId($table, $field) {
90
		return $this->getLastInsertId($table, $field);
91
	}
92
93
	/**
94
	 * alias function of select_db, changes the database we are working with.
95
	 *
96
	 * @param string $database the name of the database to use
97
	 * @return void
98
	 */
99
	public function useDb($database) {
100
		$this->selectDb($database);
101
	}
102
103
	/**
104
	 * changes the database we are working with.
105
	 *
106
	 * @param string $database the name of the database to use
107
	 * @return void
108
	 */
109
	public function selectDb($database) {
110
		$this->connect();
111
		mysqli_select_db($this->linkId, $database);
0 ignored issues
show
Bug introduced by
$this->linkId of type integer is incompatible with the type mysqli expected by parameter $link of mysqli_select_db(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

111
		mysqli_select_db(/** @scrutinizer ignore-type */ $this->linkId, $database);
Loading history...
112
	}
113
114
	/* public: connection management */
115
116
	/**
117
	 * Db::connect()
118
	 * @param string $database
119
	 * @param string $host
120
	 * @param string $user
121
	 * @param string $password
122
	 * @return int|\mysqli
123
	 */
124
	public function connect($database = '', $host = '', $user = '', $password = '') {
125
		/* Handle defaults */
126
		if ('' == $database)
127
			$database = $this->database;
128
		if ('' == $host)
129
			$host = $this->host;
130
		if ('' == $user)
131
			$user = $this->user;
132
		if ('' == $password)
133
			$password = $this->password;
134
		/* establish connection, select database */
135
		if (!is_object($this->linkId)) {
0 ignored issues
show
introduced by
The condition is_object($this->linkId) is always false.
Loading history...
136
			$this->connectionAttempt++;
137
			if ($this->connectionAttempt > 1)
138
				error_log("MySQLi Connection Attempt #{$this->connectionAttempt}/{$this->maxConnectErrors}");
139
			if ($this->connectionAttempt >= $this->maxConnectErrors) {
140
				$this->halt("connect($host, $user, \$password) failed. ".$mysqli->connect_error);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $mysqli seems to be never defined.
Loading history...
141
				return 0;
142
			}
143
			$this->linkId = mysqli_init();
144
			$this->linkId->options(MYSQLI_INIT_COMMAND, "SET NAMES {$this->characterSet} COLLATE {$this->collation}, COLLATION_CONNECTION = {$this->collation}, COLLATION_DATABASE = {$this->collation}");
145
			$this->linkId->real_connect($host, $user, $password, $database);
146
			$this->linkId->set_charset($this->characterSet);
147
			if ($this->linkId->connect_errno) {
148
				$this->halt("connect($host, $user, \$password) failed. ".$mysqli->connect_error);
149
				return 0;
150
			}
151
		}
152
		return $this->linkId;
153
	}
154
155
	/* This only affects systems not using persistent connections */
156
157
	/**
158
	 * Db::disconnect()
159
	 * @return int
160
	 */
161
	public function disconnect() {
162
		if (is_object($this->linkId))
0 ignored issues
show
introduced by
The condition is_object($this->linkId) is always false.
Loading history...
163
			return $this->linkId->close();
164
		else
165
			return 0;
166
	}
167
168
	/**
169
	 * @param $string
170
	 * @return string
171
	 */
172
	public function real_escape($string) {
173
		if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect())
0 ignored issues
show
introduced by
The condition is_resource($this->linkId) is always false.
Loading history...
174
			return mysqli_escape_string($link, $string);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $link seems to be never defined.
Loading history...
175
		return mysqli_real_escape_string($this->linkId, $string);
176
	}
177
178
	/**
179
	 * @param $string
180
	 * @return string
181
	 */
182
	public function escape($string) {
183
		return mysqli_real_escape_string($this->linkId, $string);
0 ignored issues
show
Bug introduced by
$this->linkId of type integer is incompatible with the type mysqli expected by parameter $link of mysqli_real_escape_string(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

183
		return mysqli_real_escape_string(/** @scrutinizer ignore-type */ $this->linkId, $string);
Loading history...
184
	}
185
186
	/**
187
	 * Db::dbAddslashes()
188
	 * @param mixed $str
189
	 * @return string
190
	 */
191
	public function dbAddslashes($str) {
192
		if (!isset($str) || $str == '')
193
			return '';
194
195
		return addslashes($str);
196
	}
197
198
	/**
199
	 * discard the query result
200
	 * @return void
201
	 */
202
	public function free() {
203
		if (is_resource($this->queryId))
0 ignored issues
show
introduced by
The condition is_resource($this->queryId) is always false.
Loading history...
204
			@mysqli_free_result($this->queryId);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for mysqli_free_result(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

204
			/** @scrutinizer ignore-unhandled */ @mysqli_free_result($this->queryId);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
205
		$this->queryId = 0;
206
	}
207
208
	/**
209
	 * Db::queryReturn()
210
	 *
211
	 * Sends an SQL query to the server like the normal query() command but iterates through
212
	 * any rows and returns the row or rows immediately or FALSE on error
213
	 *
214
	 * @param mixed $query SQL Query to be used
215
	 * @param string $line optionally pass __LINE__ calling the query for logging
216
	 * @param string $file optionally pass __FILE__ calling the query for logging
217
	 * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
218
	 */
219
	public function queryReturn($query, $line = '', $file = '') {
220
		$this->query($query, $line, $file);
221
		if ($this->num_rows() == 0) {
222
			return false;
223
		} elseif ($this->num_rows() == 1) {
224
			$this->next_record(MYSQL_ASSOC);
0 ignored issues
show
introduced by
The constant MYSQL_ASSOC has been deprecated: 5.5 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

224
			$this->next_record(/** @scrutinizer ignore-deprecated */ MYSQL_ASSOC);
Loading history...
225
			return $this->Record;
226
		} else {
227
			$out = [];
228
			while ($this->next_record(MYSQL_ASSOC))
0 ignored issues
show
introduced by
The constant MYSQL_ASSOC has been deprecated: 5.5 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

228
			while ($this->next_record(/** @scrutinizer ignore-deprecated */ MYSQL_ASSOC))
Loading history...
229
				$out[] = $this->Record;
230
			return $out;
231
		}
232
	}
233
234
	/**
235
	 * db:qr()
236
	 *
237
	 *  alias of queryReturn()
238
	 *
239
	 * @param mixed $query SQL Query to be used
240
	 * @param string $line optionally pass __LINE__ calling the query for logging
241
	 * @param string $file optionally pass __FILE__ calling the query for logging
242
	 * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
243
	 */
244
	public function qr($query, $line = '', $file = '') {
245
		return $this->queryReturn($query, $line, $file);
246
	}
247
248
	/**
249
	 * Db::query()
250
	 *
251
	 *  Sends an SQL query to the database
252
	 *
253
	 * @param mixed $queryString
254
	 * @param string $line
255
	 * @param string $file
256
	 * @return mixed 0 if no query or query id handler, safe to ignore this return
257
	 */
258
	public function query($queryString, $line = '', $file = '') {
259
		/* No empty queries, please, since PHP4 chokes on them. */
260
		/* The empty query string is passed on from the constructor,
261
		* when calling the class without a query, e.g. in situations
262
		* like these: '$db = new db_Subclass;'
263
		*/
264
		if ($queryString == '')
265
			return 0;
266
		if (!$this->connect()) {
267
			return 0;
268
			/* we already complained in connect() about that. */
269
		}
270
		$haltPrev = $this->haltOnError;
271
		$this->haltOnError = 'no';
272
		// New query, discard previous result.
273
		if (is_resource($this->queryId))
0 ignored issues
show
introduced by
The condition is_resource($this->queryId) is always false.
Loading history...
274
			$this->free();
275
		if ($this->Debug)
276
			printf("Debug: query = %s<br>\n", $queryString);
277
		if (isset($GLOBALS['log_queries']) && $GLOBALS['log_queries'] !== false)
278
			$this->log($queryString, $line, $file);
279
		$tries = 3;
280
		$try = 1;
281
		$this->queryId = @mysqli_query($this->linkId, $queryString, MYSQLI_STORE_RESULT);
0 ignored issues
show
Bug introduced by
$this->linkId of type integer is incompatible with the type mysqli expected by parameter $link of mysqli_query(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

281
		$this->queryId = @mysqli_query(/** @scrutinizer ignore-type */ $this->linkId, $queryString, MYSQLI_STORE_RESULT);
Loading history...
282
		$this->Row = 0;
283
		$this->Errno = @mysqli_errno($this->linkId);
0 ignored issues
show
Bug introduced by
$this->linkId of type integer is incompatible with the type mysqli expected by parameter $link of mysqli_errno(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

283
		$this->Errno = @mysqli_errno(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
284
		$this->Error = @mysqli_error($this->linkId);
0 ignored issues
show
Bug introduced by
$this->linkId of type integer is incompatible with the type mysqli expected by parameter $link of mysqli_error(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

284
		$this->Error = @mysqli_error(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
285
		while ($this->queryId === false && $try <= $tries) {
286
			$this->message = 'MySQL error '.@mysqli_errno($this->linkId).': '.@mysqli_error($this->linkId).' Query: '.$this->query;
0 ignored issues
show
Bug introduced by
The property query does not exist on MyDb\Mdb2\Db. Did you mean queryId?
Loading history...
287
			$this->error = true;
288
			@mysqli_close($this->linkId);
0 ignored issues
show
Bug introduced by
$this->linkId of type integer is incompatible with the type mysqli expected by parameter $link of mysqli_close(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

288
			@mysqli_close(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
Security Best Practice introduced by
It seems like you do not handle an error condition for mysqli_close(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

288
			/** @scrutinizer ignore-unhandled */ @mysqli_close($this->linkId);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
289
			$this->connect();
290
			$try++;
291
		}
292
		$this->haltOnError = $haltPrev;
293
		if ($this->queryId === false) {
294
			$this->emailError($queryString, 'Error #'.$this->Errno.': '.$this->Error, $line, $file);
295
		}
296
297
		// Will return nada if it fails. That's fine.
298
		return $this->queryId;
299
	}
300
301
	/* public: walk result set */
302
303
	/**
304
	 * Db::next_record()
305
	 *
306
	 * @param mixed $resultType
307
	 * @return bool
308
	 */
309
	public function next_record($resultType = MYSQLI_BOTH) {
310
		if ($this->queryId === false) {
0 ignored issues
show
introduced by
The condition $this->queryId === false is always false.
Loading history...
311
			$this->halt('next_record called with no query pending.');
312
			return 0;
313
		}
314
315
		$this->Record = @mysqli_fetch_array($this->queryId, $resultType);
0 ignored issues
show
Bug introduced by
$this->queryId of type integer is incompatible with the type mysqli_result expected by parameter $result of mysqli_fetch_array(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

315
		$this->Record = @mysqli_fetch_array(/** @scrutinizer ignore-type */ $this->queryId, $resultType);
Loading history...
316
		++$this->Row;
317
		$this->Errno = mysqli_errno($this->linkId);
0 ignored issues
show
Bug introduced by
$this->linkId of type integer is incompatible with the type mysqli expected by parameter $link of mysqli_errno(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

317
		$this->Errno = mysqli_errno(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
318
		$this->Error = mysqli_error($this->linkId);
0 ignored issues
show
Bug introduced by
$this->linkId of type integer is incompatible with the type mysqli expected by parameter $link of mysqli_error(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

318
		$this->Error = mysqli_error(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
319
320
		$stat = is_array($this->Record);
321
		if (!$stat && $this->autoFree && is_resource($this->queryId))
0 ignored issues
show
introduced by
The condition is_resource($this->queryId) is always false.
Loading history...
322
			$this->free();
323
		return $stat;
324
	}
325
326
	/* public: position in result set */
327
328
	/**
329
	 * Db::seek()
330
	 * @param integer $pos
331
	 * @return int
332
	 */
333
	public function seek($pos = 0) {
334
		$status = @mysqli_data_seek($this->queryId, $pos);
0 ignored issues
show
Bug introduced by
$this->queryId of type integer is incompatible with the type mysqli_result expected by parameter $result of mysqli_data_seek(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

334
		$status = @mysqli_data_seek(/** @scrutinizer ignore-type */ $this->queryId, $pos);
Loading history...
335
		if ($status) {
336
			$this->Row = $pos;
337
		} else {
338
			$this->halt("seek($pos) failed: result has ".$this->num_rows().' rows');
339
			/* half assed attempt to save the day,
340
			* but do not consider this documented or even
341
			* desirable behaviour.
342
			*/
343
			@mysqli_data_seek($this->queryId, $this->num_rows());
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for mysqli_data_seek(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

343
			/** @scrutinizer ignore-unhandled */ @mysqli_data_seek($this->queryId, $this->num_rows());

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
344
			$this->Row = $this->num_rows;
0 ignored issues
show
Bug Best Practice introduced by
The property num_rows does not exist on MyDb\Mdb2\Db. Did you maybe forget to declare it?
Loading history...
345
			return 0;
346
		}
347
		return 1;
348
	}
349
350
	/**
351
	 * Db::transactionBegin()
352
	 * @return bool
353
	 */
354
	public function transactionBegin() {
355
		return true;
356
	}
357
358
	/**
359
	 * Db::transactionCommit()
360
	 * @return bool
361
	 */
362
	public function transactionCommit() {
363
		return true;
364
	}
365
366
	/**
367
	 * Db::transactionAbort()
368
	 * @return bool
369
	 */
370
	public function transactionAbort() {
371
		return true;
372
	}
373
374
	/**
375
	 * Db::getLastInsertId()
376
	 * @param mixed $table
377
	 * @param mixed $field
378
	 * @return int|string
379
	 */
380
	public function getLastInsertId($table, $field) {
381
		/* This will get the last insert ID created on the current connection.  Should only be called
382
		* after an insert query is run on a table that has an auto incrementing field.  $table and
383
		* $field are required, but unused here since it's unnecessary for mysql.  For compatibility
384
		* with pgsql, the params must be supplied.
385
		*/
386
387
		if (!isset($table) || $table == '' || !isset($field) || $field == '')
388
			return -1;
389
390
		return @mysqli_insert_id($this->linkId);
0 ignored issues
show
Bug introduced by
$this->linkId of type integer is incompatible with the type mysqli expected by parameter $link of mysqli_insert_id(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

390
		return @mysqli_insert_id(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
391
	}
392
393
	/* public: table locking */
394
395
	/**
396
	 * Db::lock()
397
	 * @param mixed  $table
398
	 * @param string $mode
399
	 * @return bool|int|\mysqli_result
400
	 */
401
	public function lock($table, $mode = 'write') {
402
		$this->connect();
403
404
		$query = 'lock tables ';
405
		if (is_array($table)) {
406
			while (list($key, $value) = each($table)) {
0 ignored issues
show
Deprecated Code introduced by
The function each() has been deprecated: 7.2 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

406
			while (list($key, $value) = /** @scrutinizer ignore-deprecated */ each($table)) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
407
				if ($key == 'read' && $key != 0) {
408
					$query .= "$value read, ";
409
				} else {
410
					$query .= "$value $mode, ";
411
				}
412
			}
413
			$query = mb_substr($query, 0, -2);
414
		} else {
415
			$query .= "$table $mode";
416
		}
417
		$res = @mysqli_query($this->linkId, $query);
0 ignored issues
show
Bug introduced by
$this->linkId of type integer is incompatible with the type mysqli expected by parameter $link of mysqli_query(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

417
		$res = @mysqli_query(/** @scrutinizer ignore-type */ $this->linkId, $query);
Loading history...
418
		if (!$res) {
419
			$this->halt("lock($table, $mode) failed.");
420
			return 0;
421
		}
422
		return $res;
423
	}
424
425
	/**
426
	 * Db::unlock()
427
	 * @return bool|int|\mysqli_result
428
	 */
429
	public function unlock() {
430
		$this->connect();
431
432
		$res = @mysqli_query($this->linkId, 'unlock tables');
0 ignored issues
show
Bug introduced by
$this->linkId of type integer is incompatible with the type mysqli expected by parameter $link of mysqli_query(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

432
		$res = @mysqli_query(/** @scrutinizer ignore-type */ $this->linkId, 'unlock tables');
Loading history...
433
		if (!$res) {
434
			$this->halt('unlock() failed.');
435
			return 0;
436
		}
437
		return $res;
438
	}
439
440
	/* public: evaluate the result (size, width) */
441
442
	/**
443
	 * Db::affectedRows()
444
	 * @return int
445
	 */
446
	public function affectedRows() {
447
		return @mysqli_affected_rows($this->linkId);
0 ignored issues
show
Bug introduced by
$this->linkId of type integer is incompatible with the type mysqli expected by parameter $link of mysqli_affected_rows(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

447
		return @mysqli_affected_rows(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
448
	}
449
450
	/**
451
	 * Db::num_rows()
452
	 * @return int
453
	 */
454
	public function num_rows() {
455
		return @mysqli_num_rows($this->queryId);
0 ignored issues
show
Bug introduced by
$this->queryId of type integer is incompatible with the type mysqli_result expected by parameter $result of mysqli_num_rows(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

455
		return @mysqli_num_rows(/** @scrutinizer ignore-type */ $this->queryId);
Loading history...
456
	}
457
458
	/**
459
	 * Db::num_fields()
460
	 * @return int
461
	 */
462
	public function num_fields() {
463
		return @mysqli_num_fields($this->queryId);
0 ignored issues
show
Bug introduced by
$this->queryId of type integer is incompatible with the type mysqli_result expected by parameter $result of mysqli_num_fields(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

463
		return @mysqli_num_fields(/** @scrutinizer ignore-type */ $this->queryId);
Loading history...
464
	}
465
466
	/**
467
	 * Db::tableNames()
468
	 *
469
	 * @return array
470
	 */
471
	public function tableNames() {
472
		$return = [];
473
		$this->query('SHOW TABLES');
474
		$i = 0;
475
		while ($info = $this->queryId->fetch_row()) {
0 ignored issues
show
Bug introduced by
The method fetch_row() does not exist on integer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

475
		while ($info = $this->queryId->/** @scrutinizer ignore-call */ fetch_row()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
476
			$return[$i]['table_name'] = $info[0];
477
			$return[$i]['tablespace_name'] = $this->database;
478
			$return[$i]['database'] = $this->database;
479
			++$i;
480
		}
481
		return $return;
482
	}
483
}
484