Passed
Push — master ( 821960...93c111 )
by Joe
03:17
created

Db::queryOne()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 3
dl 0
loc 7
ccs 0
cts 6
cp 0
crap 6
rs 10
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\Mysqli\Db as MysqliDb;
14
use \MyDb\Db_Interface;
15
16
/**
17
 * Db
18
 *
19
 * @access public
20
 */
21
class Db extends MysqliDb implements Db_Interface {
22
	public $host = 'localhost';
23
	public $user = 'pdns';
24
	public $password = '';
25
	public $database = 'pdns';
26
	public $type = 'mdb2';
27
	public $error = false;
28
	public $message = '';
29
30
	/**
31
	 * Db::quote()
32
	 * @param string $text
33
	 * @param string $type
34
	 * @return string
35
	 */
36
	public function quote($text = '', $type = 'text') {
37
		switch ($type) {
38
			case 'text':
39
				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

39
				return "'".mysqli_real_escape_string(/** @scrutinizer ignore-type */ $this->linkId, $text)."'";
Loading history...
40
				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...
41
			case 'integer':
42
				return (int) $text;
43
				break;
44
			default:
45
				return $text;
46
				break;
47
		}
48
	}
49
50
	/**
51
	 * Db::queryOne()
52
	 *
53
	 * @param mixed $query
54
	 * @param string $line
55
	 * @param string $file
56
	 * @return bool
57
	 */
58
	public function queryOne($query, $line = '', $file = '') {
59
		$this->query($query, $line, $file);
60
		if ($this->num_rows() > 0) {
61
			$this->next_record();
62
			return $this->f(0);
63
		} else
64
			return 0;
65
	}
66
67
	/**
68
	 * Db::queryRow()
69
	 *
70
	 * @param mixed $query
71
	 * @param string $line
72
	 * @param string $file
73
	 * @return array|bool
74
	 */
75
	public function queryRow($query, $line = '', $file = '') {
76
		$this->query($query, $line, $file);
77
		if ($this->num_rows() > 0) {
78
			$this->next_record();
79
			return $this->Record;
80
		} else
81
			return 0;
82
	}
83
84
	/**
85
	 * Db::lastInsertId()
86
	 * @param mixed $table
87
	 * @param mixed $field
88
	 * @return int
89
	 */
90
	public function lastInsertId($table, $field) {
91
		return $this->getLastInsertId($table, $field);
92
	}
93
}
94