Passed
Push — master ( 8ee800...7f5f8c )
by Joe
03:15
created

Db::connect()   B

Complexity

Conditions 9
Paths 112

Size

Total Lines 29
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 9.3752

Importance

Changes 0
Metric Value
cc 9
eloc 23
nc 112
nop 4
dl 0
loc 29
ccs 20
cts 24
cp 0.8333
crap 9.3752
rs 7.9555
c 0
b 0
f 0
1
<?php
2
/**
3
 * MySQL Related Functionality
4
 * @author Joe Huss <[email protected]>
5
 * @copyright 2018
6
 * @package MyAdmin
7
 * @category SQL
8
 */
9
10
namespace MyDb\Mysqli;
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
	/**
22
	 * @var string
23
	 */
24
	public $type = 'mysqli';
25
26
	/**
27
	 * alias function of select_db, changes the database we are working with.
28
	 *
29
	 * @param string $database the name of the database to use
30
	 * @return void
31
	 */
32 1
	public function useDb($database) {
33 1
		$this->selectDb($database);
34
	}
35
36
	/**
37
	 * changes the database we are working with.
38
	 *
39
	 * @param string $database the name of the database to use
40
	 * @return void
41
	 */
42 1
	public function selectDb($database) {
43 1
		$this->connect();
44 1
		mysqli_select_db($this->linkId, $database);
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_select_db() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

44
		mysqli_select_db(/** @scrutinizer ignore-type */ $this->linkId, $database);
Loading history...
45
	}
46
47
	/* public: connection management */
48
49
	/**
50
	 * Db::connect()
51
	 * @param string $database
52
	 * @param string $host
53
	 * @param string $user
54
	 * @param string $password
55
	 * @return int|\mysqli
56
	 */
57 26
	public function connect($database = '', $host = '', $user = '', $password = '') {
58
		/* Handle defaults */
59 26
		if ($database == '')
60 26
			$database = $this->database;
61 26
		if ($host == '')
62 26
			$host = $this->host;
63 26
		if ($user == '')
64 26
			$user = $this->user;
65 26
		if ($password == '')
66 26
			$password = $this->password;
67
		/* establish connection, select database */
68 26
		if (!is_object($this->linkId)) {
69 26
			$this->connectionAttempt++;
70 26
			if ($this->connectionAttempt > 1)
71 6
				error_log("MySQLi Connection Attempt #{$this->connectionAttempt}/{$this->maxConnectErrors}");
72 26
			if ($this->connectionAttempt >= $this->maxConnectErrors) {
73
				$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...
74
				return 0;
75
			}
76 26
			$this->linkId = mysqli_init();
77 26
			$this->linkId->options(MYSQLI_INIT_COMMAND, "SET NAMES {$this->characterSet} COLLATE {$this->collation}, COLLATION_CONNECTION = {$this->collation}, COLLATION_DATABASE = {$this->collation}");
78 26
			$this->linkId->real_connect($host, $user, $password, $database);
79 26
			$this->linkId->set_charset($this->characterSet);
80 26
			if ($this->linkId->connect_errno) {
81
				$this->halt("connect($host, $user, \$password) failed. ".$mysqli->connect_error);
82
				return 0;
83
			}
84
		}
85 26
		return $this->linkId;
86
	}
87
88
	/**
89
	 * Db::disconnect()
90
	 * @return bool
91
	 */
92 1
	public function disconnect() {
93 1
		$return = method_exists($this->linkId, 'close') ? $this->linkId->close() : false;
94 1
		$this->linkId = 0;
95 1
		return $return;
96
	}
97
98
	/**
99
	 * @param $string
100
	 * @return string
101
	 */
102 2
	public function real_escape($string = '') {
103 2
		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...
104
			return $this->escape($string);
105 2
		return mysqli_real_escape_string($this->linkId, $string);
106
	}
107
108
	/**
109
	 * discard the query result
110
	 * @return void
111
	 */
112 1
	public function free() {
113 1
		if (is_resource($this->queryId))
0 ignored issues
show
introduced by
The condition is_resource($this->queryId) is always false.
Loading history...
114
			@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

114
			/** @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...
115 1
		$this->queryId = 0;
116
	}
117
118
	/**
119
	 * Db::queryReturn()
120
	 *
121
	 * Sends an SQL query to the server like the normal query() command but iterates through
122
	 * any rows and returns the row or rows immediately or FALSE on error
123
	 *
124
	 * @param mixed $query SQL Query to be used
125
	 * @param string $line optionally pass __LINE__ calling the query for logging
126
	 * @param string $file optionally pass __FILE__ calling the query for logging
127
	 * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
128
	 */
129 1
	public function queryReturn($query, $line = '', $file = '') {
130 1
		$this->query($query, $line, $file);
131 1
		if ($this->num_rows() == 0) {
132 1
			return false;
133 1
		} elseif ($this->num_rows() == 1) {
134 1
			$this->next_record(MYSQLI_ASSOC);
135 1
			return $this->Record;
136
		} else {
137 1
			$out = [];
138 1
			while ($this->next_record(MYSQLI_ASSOC))
139 1
				$out[] = $this->Record;
140 1
			return $out;
141
		}
142
	}
143
144
	/**
145
	 * db:qr()
146
	 *
147
	 *  alias of queryReturn()
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 1
	public function qr($query, $line = '', $file = '') {
155 1
		return $this->queryReturn($query, $line, $file);
156
	}
157
158
	/**
159
	 * creates a prepaired statement from query
160
	 *
161
	 * @param string $query sql wuery like INSERT INTO table (col) VALUES (?)  or  SELECT * from table WHERE col1 = ? and col2 = ?  or  UPDATE table SET col1 = ?, col2 = ? WHERE col3 = ?
162
	 * @return int|\MyDb\Mysqli\mysqli_stmt
0 ignored issues
show
Bug introduced by
The type MyDb\Mysqli\mysqli_stmt was not found. Did you mean mysqli_stmt? If so, make sure to prefix the type with \.
Loading history...
163
	 */
164 1
	public function prepare($query) {
165 1
		if (!$this->connect())
166
			return 0;
167 1
		$haltPrev = $this->haltOnError;
0 ignored issues
show
Unused Code introduced by
The assignment to $haltPrev is dead and can be removed.
Loading history...
168 1
		$this->haltOnError = 'no';
169 1
		return mysqli_prepare($this->linkId, $query);
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_prepare() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

169
		return mysqli_prepare(/** @scrutinizer ignore-type */ $this->linkId, $query);
Loading history...
170
	}
171
172
	/**
173
	 * Db::query()
174
	 *
175
	 *  Sends an SQL query to the database
176
	 *
177
	 * @param mixed $queryString
178
	 * @param string $line
179
	 * @param string $file
180
	 * @return mixed 0 if no query or query id handler, safe to ignore this return
181
	 */
182 10
	public function query($queryString, $line = '', $file = '') {
183
		/* No empty queries, please, since PHP4 chokes on them. */
184
		/* The empty query string is passed on from the constructor,
185
		* when calling the class without a query, e.g. in situations
186
		* like these: '$db = new db_Subclass;'
187
		*/
188 10
		if ($queryString == '')
189 1
			return 0;
190 10
		if (!$this->connect()) {
191
			return 0;
192
			/* we already complained in connect() about that. */
193
		}
194 10
		$haltPrev = $this->haltOnError;
195 10
		$this->haltOnError = 'no';
196
		// New query, discard previous result.
197 10
		if (is_resource($this->queryId))
0 ignored issues
show
introduced by
The condition is_resource($this->queryId) is always false.
Loading history...
198
			$this->free();
199 10
		if ($this->Debug)
200 1
			printf("Debug: query = %s<br>\n", $queryString);
201 10
		if (!isset($GLOBALS['db_queries']))
202 1
			$GLOBALS['db_queries'] = array();
203 10
		$GLOBALS['db_queries'][] = $queryString;
204 10
		if (isset($GLOBALS['log_queries']) && $GLOBALS['log_queries'] !== false)
205
			$this->log($queryString, $line, $file);
206 10
		$tries = 3;
207 10
		$try = 0;
208 10
		$this->queryId = false;
209 10
		while ((null === $this->queryId || $this->queryId === false) && $try <= $tries) {
210 10
			$try++;
211 10
			if ($try > 1) {
212
				@mysqli_close($this->linkId);
0 ignored issues
show
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

212
				/** @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...
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_close() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

212
				@mysqli_close(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
213
				$this->connect();
214
			}
215 10
			$this->queryId = @mysqli_query($this->linkId, $queryString, MYSQLI_STORE_RESULT);
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_query() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

215
			$this->queryId = @mysqli_query(/** @scrutinizer ignore-type */ $this->linkId, $queryString, MYSQLI_STORE_RESULT);
Loading history...
216 10
			$this->Row = 0;
217 10
			$this->Errno = @mysqli_errno($this->linkId);
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_errno() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

217
			$this->Errno = @mysqli_errno(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
218 10
			$this->Error = @mysqli_error($this->linkId);
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_error() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

218
			$this->Error = @mysqli_error(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
219 10
			if ($try == 1 && (null === $this->queryId || $this->queryId === false)) {
220
				$this->emailError($queryString, 'Error #'.$this->Errno.': '.$this->Error, $line, $file);
221
			}
222
		}
223 10
		$this->haltOnError = $haltPrev;
224 10
		if (null === $this->queryId || $this->queryId === false)
225
			$this->halt('', $line, $file);
226
227
		// Will return nada if it fails. That's fine.
228 10
		return $this->queryId;
229
	}
230
231
	/**
232
	 * @return array|null|object
233
	 */
234 1
	public function fetchObject() {
235 1
		$this->Record = @mysqli_fetch_object($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_fetch_object(). ( Ignorable by Annotation )

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

235
		$this->Record = @mysqli_fetch_object(/** @scrutinizer ignore-type */ $this->queryId);
Loading history...
236 1
		return $this->Record;
237
	}
238
239
	/* public: walk result set */
240
241
	/**
242
	 * Db::next_record()
243
	 *
244
	 * @param mixed $resultType
245
	 * @return bool
246
	 */
247 6
	public function next_record($resultType = MYSQLI_BOTH) {
248 6
		if ($this->queryId === false) {
0 ignored issues
show
introduced by
The condition $this->queryId === false is always false.
Loading history...
249
			$this->haltmsg('next_record called with no query pending.');
250
			return 0;
251
		}
252
253 6
		$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

253
		$this->Record = @mysqli_fetch_array(/** @scrutinizer ignore-type */ $this->queryId, $resultType);
Loading history...
254 6
		++$this->Row;
255 6
		$this->Errno = mysqli_errno($this->linkId);
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_errno() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

255
		$this->Errno = mysqli_errno(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
256 6
		$this->Error = mysqli_error($this->linkId);
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_error() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

256
		$this->Error = mysqli_error(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
257
258 6
		$stat = is_array($this->Record);
259 6
		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...
260
			$this->free();
261 6
		return $stat;
262
	}
263
264
	/**
265
	 * switch to position in result set
266
	 * 
267
	 * @param integer $pos the row numbe starting at 0 to switch to
268
	 * @return bool whetherit was successfu or not.
269
	 */
270 1
	public function seek($pos = 0) {
271 1
		$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

271
		$status = @mysqli_data_seek(/** @scrutinizer ignore-type */ $this->queryId, $pos);
Loading history...
272 1
		if ($status) {
273 1
			$this->Row = $pos;
274
		} else {
275 1
			$this->haltmsg("seek({$pos}) failed: result has ".$this->num_rows().' rows', __LINE__, __FILE__);
276
			/* half assed attempt to save the day, but do not consider this documented or even desirable behaviour. */
277 1
			$rows = $this->num_rows();
278 1
			@mysqli_data_seek($this->queryId, $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

278
			/** @scrutinizer ignore-unhandled */ @mysqli_data_seek($this->queryId, $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...
279 1
			$this->Row = $rows;
280 1
			return false;
281
		}
282 1
		return true;
283
	}
284
285
	/**
286
	 * Initiates a transaction
287
	 *
288
	 * @return bool
289
	 */
290 26
	public function transactionBegin() {
291 26
		if (version_compare(PHP_VERSION, '5.5.0') < 0)
292
			return true;
293 26
		if (!$this->connect())
294
			return 0;
295 26
		return mysqli_begin_transaction($this->linkId);
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_begin_transaction() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

295
		return mysqli_begin_transaction(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
296
	}
297
298
	/**
299
	 * Commits a transaction
300
	 *
301
	 * @return bool
302
	 */
303 1
	public function transactionCommit() {
304 1
		if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0)
305
			return true;
306 1
		return mysqli_commit($this->linkId);
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_commit() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

306
		return mysqli_commit(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
307
	}
308
309
	/**
310
	 * Rolls back a transaction
311
	 *
312
	 * @return bool
313
	 */
314 26
	public function transactionAbort() {
315 26
		if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0)
316
			return true;
317 26
		return mysqli_rollback($this->linkId);
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_rollback() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

317
		return mysqli_rollback(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
318
	}
319
320
	/**
321
	 * This will get the last insert ID created on the current connection.  Should only be called after an insert query is
322
	 * run on a table that has an auto incrementing field.  $table and $field are required, but unused here since it's
323
	 * unnecessary for mysql.  For compatibility with pgsql, the params must be supplied.
324
	 *
325
	 * @param string $table
326
	 * @param string $field
327
	 * @return int|string
328
	 */
329 2
	public function getLastInsertId($table, $field) {
330 2
		if (!isset($table) || $table == '' || !isset($field) || $field == '')
331
			return -1;
332
333 2
		return @mysqli_insert_id($this->linkId);
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_insert_id() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

333
		return @mysqli_insert_id(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
334
	}
335
336
	/* public: table locking */
337
338
	/**
339
	 * Db::lock()
340
	 * @param mixed  $table
341
	 * @param string $mode
342
	 * @return bool|int|\mysqli_result
343
	 */
344 1
	public function lock($table, $mode = 'write') {
345 1
		$this->connect();
346 1
		$query = 'lock tables ';
347 1
		if (is_array($table)) {
348 1
			foreach ($table as $key => $value) {
349 1
				if ($key == 'read' && $key != 0) {
350
					$query .= "$value read, ";
351
				} else {
352 1
					$query .= "$value $mode, ";
353
				}
354
			}
355 1
			$query = mb_substr($query, 0, -2);
356
		} else {
357 1
			$query .= "$table $mode";
358
		}
359 1
		$res = @mysqli_query($this->linkId, $query);
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_query() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

359
		$res = @mysqli_query(/** @scrutinizer ignore-type */ $this->linkId, $query);
Loading history...
360 1
		if (!$res) {
361
			$this->halt("lock($table, $mode) failed.");
362
			return 0;
363
		}
364 1
		return $res;
365
	}
366
367
	/**
368
	 * Db::unlock()
369
	 * @param bool $haltOnError optional, defaults to TRUE, whether or not to halt on error
370
	 * @return bool|int|\mysqli_result
371
	 */
372 2
	public function unlock($haltOnError = true) {
373 2
		$this->connect();
374
375 2
		$res = @mysqli_query($this->linkId, 'unlock tables');
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_query() does only seem to accept mysqli, maybe add an additional type check? ( Ignorable by Annotation )

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

375
		$res = @mysqli_query(/** @scrutinizer ignore-type */ $this->linkId, 'unlock tables');
Loading history...
376 2
		if ($haltOnError === true && !$res) {
377
			$this->halt('unlock() failed.');
378
			return 0;
379
		}
380 2
		return $res;
381
	}
382
383
	/* public: evaluate the result (size, width) */
384
385
	/**
386
	 * Db::affectedRows()
387
	 * @return int
388
	 */
389 2
	public function affectedRows() {
390 2
		return @mysqli_affected_rows($this->linkId);
0 ignored issues
show
Bug introduced by
It seems like $this->linkId can also be of type integer; however, parameter $link of mysqli_affected_rows() does only seem to accept mysqli, maybe add an additional type check? ( 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_affected_rows(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
391
	}
392
393
	/**
394
	 * Db::num_rows()
395
	 * @return int
396
	 */
397 6
	public function num_rows() {
398 6
		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

398
		return @mysqli_num_rows(/** @scrutinizer ignore-type */ $this->queryId);
Loading history...
399
	}
400
401
	/**
402
	 * Db::num_fields()
403
	 * @return int
404
	 */
405 1
	public function num_fields() {
406 1
		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

406
		return @mysqli_num_fields(/** @scrutinizer ignore-type */ $this->queryId);
Loading history...
407
	}
408
409
	/**
410
	 * gets an array of the table names in teh current datase
411
	 *
412
	 * @return array
413
	 */
414 1
	public function tableNames() {
415 1
		$return = [];
416 1
		$this->query('SHOW TABLES');
417 1
		$i = 0;
418 1
		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

418
		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...
419 1
			$return[$i]['table_name'] = $info[0];
420 1
			$return[$i]['tablespace_name'] = $this->database;
421 1
			$return[$i]['database'] = $this->database;
422 1
			++$i;
423
		}
424 1
		return $return;
425
	}
426
}
427
428
/**
429
 * @param $result
430
 * @param $row
431
 * @param int|string $field
432
 * @return bool
433
 */
434
/*
435
function mysqli_result($result, $row, $field = 0) {
436
	if ($result === false) return false;
437
	if ($row >= mysqli_num_rows($result)) return false;
438
	if (is_string($field) && !(mb_strpos($field, '.') === false)) {
439
		$tField = explode('.', $field);
440
		$field = -1;
441
		$tFields = mysqli_fetch_fields($result);
442
		for ($id = 0, $idMax = mysqli_num_fields($result); $id < $idMax; $id++) {
443
			if ($tFields[$id]->table == $tField[0] && $tFields[$id]->name == $tField[1]) {
444
				$field = $id;
445
				break;
446
			}
447
		}
448
		if ($field == -1) return false;
449
	}
450
	mysqli_data_seek($result, $row);
451
	$line = mysqli_fetch_array($result);
452
	return isset($line[$field]) ? $line[$field] : false;
453
}
454
*/
455