Passed
Push — master ( 4f1d2e...ef95bd )
by Joe
02:36
created

Db::lock()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6.288

Importance

Changes 0
Metric Value
cc 6
eloc 16
nc 4
nop 2
dl 0
loc 21
ccs 12
cts 15
cp 0.8
crap 6.288
rs 9.1111
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 17
	public function connect($database = '', $host = '', $user = '', $password = '') {
58
		/* Handle defaults */
59 17
		if ($database == '')
60 17
			$database = $this->database;
61 17
		if ($host == '')
62 17
			$host = $this->host;
63 17
		if ($user == '')
64 17
			$user = $this->user;
65 17
		if ($password == '')
66 17
			$password = $this->password;
67
		/* establish connection, select database */
68 17
		if (!is_object($this->linkId)) {
69 17
			$this->connectionAttempt++;
70 17
			if ($this->connectionAttempt > 1)
71 4
				error_log("MySQLi Connection Attempt #{$this->connectionAttempt}/{$this->maxConnectErrors}");
72 17
			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 17
			$this->linkId = mysqli_init();
77 17
			$this->linkId->options(MYSQLI_INIT_COMMAND, "SET NAMES {$this->characterSet} COLLATE {$this->collation}, COLLATION_CONNECTION = {$this->collation}, COLLATION_DATABASE = {$this->collation}");
78 17
			$this->linkId->real_connect($host, $user, $password, $database);
79 17
			$this->linkId->set_charset($this->characterSet);
80 17
			if ($this->linkId->connect_errno) {
81
				$this->halt("connect($host, $user, \$password) failed. ".$mysqli->connect_error);
82
				return 0;
83
			}
84
		}
85 17
		return $this->linkId;
86
	}
87
88
	/**
89
	 * Db::disconnect()
90
	 * @return bool
91
	 */
92 1
	public function disconnect() {
93 1
		$return = is_resource($this->linkId) ? $this->linkId->close() : false;
0 ignored issues
show
introduced by
The condition is_resource($this->linkId) is always false.
Loading history...
94 1
		$this->linkId = 0;
95 1
		return $return;
96
	}
97
98
	/**
99
	 * @param $string
100
	 * @return string
101
	 */
102 1
	public function real_escape($string) {
103 1
		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 1
		return mysqli_real_escape_string($this->linkId, $string);
106
	}
107
108
	/**
109
	 * @param $string
110
	 * @return string
111
	 */
112 1
	public function escape($string) {
113
		//if (function_exists('mysql_escape_string'))
114
			//return mysql_escape_string($string);
115 1
		return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $string);
116
	}
117
118
	/**
119
	 * Db::dbAddslashes()
120
	 * @param mixed $str
121
	 * @return string
122
	 */
123 1
	public function dbAddslashes($str = '') {
124 1
		if ($str == '')
125 1
			return '';
126 1
		return addslashes($str);
127
	}
128
129
	/* public: discard the query result */
130
131
	/**
132
	 * Db::free()
133
	 * @return void
134
	 */
135 1
	public function free() {
136 1
		if (is_resource($this->queryId))
0 ignored issues
show
introduced by
The condition is_resource($this->queryId) is always false.
Loading history...
137
			@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

137
			/** @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...
138 1
		$this->queryId = 0;
139
	}
140
141
	/**
142
	 * Db::queryReturn()
143
	 *
144
	 * Sends an SQL query to the server like the normal query() command but iterates through
145
	 * any rows and returns the row or rows immediately or FALSE on error
146
	 *
147
	 * @param mixed $query SQL Query to be used
148
	 * @param string $line optionally pass __LINE__ calling the query for logging
149
	 * @param string $file optionally pass __FILE__ calling the query for logging
150
	 * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
151
	 */
152 1
	public function queryReturn($query, $line = '', $file = '') {
153 1
		$this->query($query, $line, $file);
154 1
		if ($this->num_rows() == 0) {
155 1
			return false;
156 1
		} elseif ($this->num_rows() == 1) {
157 1
			$this->next_record(MYSQLI_ASSOC);
158 1
			return $this->Record;
159
		} else {
160 1
			$out = [];
161 1
			while ($this->next_record(MYSQLI_ASSOC))
162 1
				$out[] = $this->Record;
163 1
			return $out;
164
		}
165
	}
166
167
	/**
168
	 * db:qr()
169
	 *
170
	 *  alias of queryReturn()
171
	 *
172
	 * @param mixed $query SQL Query to be used
173
	 * @param string $line optionally pass __LINE__ calling the query for logging
174
	 * @param string $file optionally pass __FILE__ calling the query for logging
175
	 * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only
176
	 */
177 1
	public function qr($query, $line = '', $file = '') {
178 1
		return $this->queryReturn($query, $line, $file);
179
	}
180
181
	/**
182
	 * creates a prepaired statement from query
183
	 *
184
	 * @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 = ?
185
	 * @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...
186
	 */
187 1
	public function prepare($query) {
188 1
		if (!$this->connect())
189
			return 0;
190 1
		$haltPrev = $this->haltOnError;
0 ignored issues
show
Unused Code introduced by
The assignment to $haltPrev is dead and can be removed.
Loading history...
191 1
		$this->haltOnError = 'no';
192 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

192
		return mysqli_prepare(/** @scrutinizer ignore-type */ $this->linkId, $query);
Loading history...
193
	}
194
195
	/**
196
	 * Db::query()
197
	 *
198
	 *  Sends an SQL query to the database
199
	 *
200
	 * @param mixed $queryString
201
	 * @param string $line
202
	 * @param string $file
203
	 * @return mixed 0 if no query or query id handler, safe to ignore this return
204
	 */
205 7
	public function query($queryString, $line = '', $file = '') {
206
		/* No empty queries, please, since PHP4 chokes on them. */
207
		/* The empty query string is passed on from the constructor,
208
		* when calling the class without a query, e.g. in situations
209
		* like these: '$db = new db_Subclass;'
210
		*/
211 7
		if ($queryString == '')
212 1
			return 0;
213 7
		if (!$this->connect()) {
214
			return 0;
215
			/* we already complained in connect() about that. */
216
		}
217 7
		$haltPrev = $this->haltOnError;
218 7
		$this->haltOnError = 'no';
219
		// New query, discard previous result.
220 7
		if (is_resource($this->queryId))
0 ignored issues
show
introduced by
The condition is_resource($this->queryId) is always false.
Loading history...
221
			$this->free();
222 7
		if ($this->Debug)
223 7
			printf("Debug: query = %s<br>\n", $queryString);
224 7
		if (isset($GLOBALS['log_queries']) && $GLOBALS['log_queries'] !== false)
225
			$this->log($queryString, $line, $file);
226 7
		$tries = 3;
227 7
		$try = 0;
228 7
		$this->queryId = false;
229 7
		while ((null === $this->queryId || $this->queryId === false) && $try <= $tries) {
230 7
			$try++;
231 7
			if ($try > 1) {
232
				@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

232
				/** @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

232
				@mysqli_close(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
233
				$this->connect();
234
			}
235 7
			$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

235
			$this->queryId = @mysqli_query(/** @scrutinizer ignore-type */ $this->linkId, $queryString, MYSQLI_STORE_RESULT);
Loading history...
236 7
			$this->Row = 0;
237 7
			$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

237
			$this->Errno = @mysqli_errno(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
238 7
			$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

238
			$this->Error = @mysqli_error(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
239 7
			if ($try == 1 && (null === $this->queryId || $this->queryId === false)) {
240
				$this->emailError($queryString, 'Error #'.$this->Errno.': '.$this->Error, $line, $file);
241
			}
242
		}
243 7
		$this->haltOnError = $haltPrev;
244 7
		if (null === $this->queryId || $this->queryId === false)
245
			$this->halt('', $line, $file);
246
247
		// Will return nada if it fails. That's fine.
248 7
		return $this->queryId;
249
	}
250
251
	/**
252
	 * @return array|null|object
253
	 */
254 1
	public function fetchObject() {
255 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

255
		$this->Record = @mysqli_fetch_object(/** @scrutinizer ignore-type */ $this->queryId);
Loading history...
256 1
		return $this->Record;
257
	}
258
259
	/* public: walk result set */
260
261
	/**
262
	 * Db::next_record()
263
	 *
264
	 * @param mixed $resultType
265
	 * @return bool
266
	 */
267 4
	public function next_record($resultType = MYSQLI_BOTH) {
268 4
		if ($this->queryId === false) {
0 ignored issues
show
introduced by
The condition $this->queryId === false is always false.
Loading history...
269
			$this->halt('next_record called with no query pending.');
270
			return 0;
271
		}
272
273 4
		$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

273
		$this->Record = @mysqli_fetch_array(/** @scrutinizer ignore-type */ $this->queryId, $resultType);
Loading history...
274 4
		++$this->Row;
275 4
		$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

275
		$this->Errno = mysqli_errno(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
276 4
		$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

276
		$this->Error = mysqli_error(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
277
278 4
		$stat = is_array($this->Record);
279 4
		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...
280
			$this->free();
281 4
		return $stat;
282
	}
283
284
	/* public: position in result set */
285
286
	/**
287
	 * Db::seek()
288
	 * @param integer $pos
289
	 * @return int
290
	 */
291
	public function seek($pos = 0) {
292
		$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

292
		$status = @mysqli_data_seek(/** @scrutinizer ignore-type */ $this->queryId, $pos);
Loading history...
293
		if ($status) {
294
			$this->Row = $pos;
295
		} else {
296
			$this->halt("seek($pos) failed: result has ".$this->num_rows().' rows');
297
			/* half assed attempt to save the day,
298
			* but do not consider this documented or even
299
			* desirable behaviour.
300
			*/
301
			@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

301
			/** @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...
302
			$this->Row = $this->num_rows;
0 ignored issues
show
Bug Best Practice introduced by
The property num_rows does not exist on MyDb\Mysqli\Db. Did you maybe forget to declare it?
Loading history...
303
			return 0;
304
		}
305
		return 1;
306
	}
307
308
	/**
309
	 * Initiates a transaction
310
	 *
311
	 * @return bool
312
	 */
313 17
	public function transactionBegin() {
314 17
		if (version_compare(PHP_VERSION, '5.5.0') < 0)
315
			return true;
316 17
		if (!$this->connect())
317
			return 0;
318 17
		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

318
		return mysqli_begin_transaction(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
319
	}
320
321
	/**
322
	 * Commits a transaction
323
	 *
324
	 * @return bool
325
	 */
326 1
	public function transactionCommit() {
327 1
		if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0)
328
			return true;
329 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

329
		return mysqli_commit(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
330
	}
331
332
	/**
333
	 * Rolls back a transaction
334
	 *
335
	 * @return bool
336
	 */
337 17
	public function transactionAbort() {
338 17
		if (version_compare(PHP_VERSION, '5.5.0') < 0 || $this->linkId === 0)
339
			return true;
340 17
		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

340
		return mysqli_rollback(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
341
	}
342
343
	/**
344
	 * This will get the last insert ID created on the current connection.  Should only be called after an insert query is
345
	 * run on a table that has an auto incrementing field.  $table and $field are required, but unused here since it's
346
	 * unnecessary for mysql.  For compatibility with pgsql, the params must be supplied.
347
	 *
348
	 * @param string $table
349
	 * @param string $field
350
	 * @return int|string
351
	 */
352 1
	public function getLastInsertId($table, $field) {
353 1
		if (!isset($table) || $table == '' || !isset($field) || $field == '')
354
			return -1;
355
356 1
		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

356
		return @mysqli_insert_id(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
357
	}
358
359
	/* public: table locking */
360
361
	/**
362
	 * Db::lock()
363
	 * @param mixed  $table
364
	 * @param string $mode
365
	 * @return bool|int|\mysqli_result
366
	 */
367 1
	public function lock($table, $mode = 'write') {
368 1
		$this->connect();
369 1
		$query = 'lock tables ';
370 1
		if (is_array($table)) {
371 1
			foreach ($table as $key => $value) {
372 1
				if ($key == 'read' && $key != 0) {
373
					$query .= "$value read, ";
374
				} else {
375 1
					$query .= "$value $mode, ";
376
				}
377
			}
378 1
			$query = mb_substr($query, 0, -2);
379
		} else {
380 1
			$query .= "$table $mode";
381
		}
382 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

382
		$res = @mysqli_query(/** @scrutinizer ignore-type */ $this->linkId, $query);
Loading history...
383 1
		if (!$res) {
384
			$this->halt("lock($table, $mode) failed.");
385
			return 0;
386
		}
387 1
		return $res;
388
	}
389
390
	/**
391
	 * Db::unlock()
392
	 * @param bool $haltOnError optional, defaults to TRUE, whether or not to halt on error
393
	 * @return bool|int|\mysqli_result
394
	 */
395 1
	public function unlock($haltOnError = true) {
396 1
		$this->connect();
397
398 1
		$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

398
		$res = @mysqli_query(/** @scrutinizer ignore-type */ $this->linkId, 'unlock tables');
Loading history...
399 1
		if ($haltOnError === true && !$res) {
400
			$this->halt('unlock() failed.');
401
			return 0;
402
		}
403 1
		return $res;
404
	}
405
406
	/* public: evaluate the result (size, width) */
407
408
	/**
409
	 * Db::affectedRows()
410
	 * @return int
411
	 */
412 2
	public function affectedRows() {
413 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

413
		return @mysqli_affected_rows(/** @scrutinizer ignore-type */ $this->linkId);
Loading history...
414
	}
415
416
	/**
417
	 * Db::num_rows()
418
	 * @return int
419
	 */
420 3
	public function num_rows() {
421 3
		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

421
		return @mysqli_num_rows(/** @scrutinizer ignore-type */ $this->queryId);
Loading history...
422
	}
423
424
	/**
425
	 * Db::num_fields()
426
	 * @return int
427
	 */
428 1
	public function num_fields() {
429 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

429
		return @mysqli_num_fields(/** @scrutinizer ignore-type */ $this->queryId);
Loading history...
430
	}
431
432
	/**
433
	 * gets an array of the table names in teh current datase
434
	 *
435
	 * @return array
436
	 */
437 1
	public function tableNames() {
438 1
		$return = [];
439 1
		$this->query('SHOW TABLES');
440 1
		$i = 0;
441 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

441
		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...
442 1
			$return[$i]['table_name'] = $info[0];
443 1
			$return[$i]['tablespace_name'] = $this->database;
444 1
			$return[$i]['database'] = $this->database;
445 1
			++$i;
446
		}
447 1
		return $return;
448
	}
449
}
450
451
/**
452
 * @param $result
453
 * @param $row
454
 * @param int|string $field
455
 * @return bool
456
 */
457
/*
458
function mysqli_result($result, $row, $field = 0) {
459
	if ($result === false) return false;
460
	if ($row >= mysqli_num_rows($result)) return false;
461
	if (is_string($field) && !(mb_strpos($field, '.') === false)) {
462
		$tField = explode('.', $field);
463
		$field = -1;
464
		$tFields = mysqli_fetch_fields($result);
465
		for ($id = 0, $idMax = mysqli_num_fields($result); $id < $idMax; $id++) {
466
			if ($tFields[$id]->table == $tField[0] && $tFields[$id]->name == $tField[1]) {
467
				$field = $id;
468
				break;
469
			}
470
		}
471
		if ($field == -1) return false;
472
	}
473
	mysqli_data_seek($result, $row);
474
	$line = mysqli_fetch_array($result);
475
	return isset($line[$field]) ? $line[$field] : false;
476
}
477
*/