ezSQL_mysqli::query()   F
last analyzed

Complexity

Conditions 18
Paths 110

Size

Total Lines 131

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 131
c 0
b 0
f 0
rs 3.8266
cc 18
nc 110
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Mmanager\Extensions\Database;
3
	/**********************************************************************
4
	*  Author: Juergen Bouché ([email protected])
5
	*  Web...: http://www.juergenbouche.de
6
	*  Name..: ezSQL_mysqli
7
	*  Desc..: mySQLi component (part of ezSQL database abstraction library)
8
	*
9
	*/
10
11
	/**********************************************************************
12
	*  ezSQL error strings - mySQLi
13
	*/
14
    
15
	global $ezsql_mysqli_str;
16
17
	$ezsql_mysqli_str = array(
18
		1 => 'Require $dbuser and $dbpassword to connect to a database server',
19
		2 => 'Error establishing mySQLi database connection. Correct user/password? Correct hostname? Database server running?',
20
		3 => 'Require $dbname to select a database',
21
		4 => 'mySQLi database connection is not active',
22
		5 => 'Unexpected error while trying to select database'
23
	);
24
25
	/**********************************************************************
26
	*  ezSQL Database specific class - mySQLi
27
	*/
28
29
	if ( ! function_exists('mysqli_connect')) die('<b>Fatal Error:</b> ezSQL_mysql requires mySQLi Lib to be compiled and or linked in to the PHP engine');
30
	if ( ! class_exists('ezSQLcore')) die('<b>Fatal Error:</b> ezSQL_mysql requires ezSQLcore (ez_sql_core.php) to be included/loaded before it can be used');
31
32
	class ezSQL_mysqli extends ezSQLcore
33
	{
34
35
		var $dbuser = false;
36
		var $dbpassword = false;
37
		var $dbname = false;
38
		var $dbhost = false;
39
		var $dbport = false;
40
		var $encoding = false;
41
		var $rows_affected = false;
42
43
		/**********************************************************************
44
		*  Constructor - allow the user to perform a quick connect at the
45
		*  same time as initialising the ezSQL_mysqli class
46
		*/
47
48
		function __construct($dbuser = '', $dbpassword = '', $dbname = '', $dbhost = 'localhost', $encoding = '')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
49
		{
50
			$this->dbuser = $dbuser;
0 ignored issues
show
Documentation Bug introduced by
The property $dbuser was declared of type boolean, but $dbuser is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
51
			$this->dbpassword = $dbpassword;
0 ignored issues
show
Documentation Bug introduced by
The property $dbpassword was declared of type boolean, but $dbpassword is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
52
			$this->dbname = $dbname;
0 ignored issues
show
Documentation Bug introduced by
The property $dbname was declared of type boolean, but $dbname is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
53
			list($this->dbhost, $this->dbport) = $this->get_host_port($dbhost, 3306);
0 ignored issues
show
Documentation introduced by
3306 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
54
			$this->encoding = $encoding;
0 ignored issues
show
Documentation Bug introduced by
The property $encoding was declared of type boolean, but $encoding is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
55
		}
56
57
		/**********************************************************************
58
		*  Short hand way to connect to mySQL database server
59
		*  and select a mySQL database at the same time
60
		*/
61
62
		function quick_connect($dbuser = '', $dbpassword = '', $dbname = '', $dbhost = 'localhost', $dbport = '3306', $encoding = '')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
63
		{
64
			$return_val = false;
65
			if ( ! $this->connect($dbuser, $dbpassword, $dbhost, $dbport));
0 ignored issues
show
Documentation introduced by
$dbport is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
66
			else if ( ! $this->select($dbname, $encoding));
67
			else $return_val = true;
68
			return $return_val;
69
		}
70
71
		/**********************************************************************
72
		*  Try to connect to mySQL database server
73
		*/
74
75
		function connect($dbuser = '', $dbpassword = '', $dbhost = 'localhost', $dbport = false)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
76
		{
77
			global $ezsql_mysqli_str; $return_val = false;
78
			
79
			// Keep track of how long the DB takes to connect
80
			$this->timer_start('db_connect_time');
81
			
82
			// If port not specified (new connection issued), get it
83
			if ( ! $dbport) {
84
				list($dbhost, $dbport) = $this->get_host_port($dbhost, 3306);
0 ignored issues
show
Documentation introduced by
3306 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
			}
86
			
87
			// Must have a user and a password
88
			if ( ! $dbuser)
89
			{
90
				$this->register_error($ezsql_mysqli_str[1].' in '.__FILE__.' on line '.__LINE__);
91
				$this->show_errors ? trigger_error($ezsql_mysqli_str[1], E_USER_WARNING) : null;
92
			}
93
			// Try to establish the server database handle
94
			else
95
			{
96
				$this->dbh = new \Mysqli($dbhost, $dbuser, $dbpassword, '', $dbport);
0 ignored issues
show
Bug introduced by
The property dbh does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
97
				// Check for connection problem
98
				if ($this->dbh->connect_errno)
99
				{
100
					$this->register_error($ezsql_mysqli_str[2].' in '.__FILE__.' on line '.__LINE__);
101
					$this->show_errors ? trigger_error($ezsql_mysqli_str[2], E_USER_WARNING) : null;
102
				}
103
				else
104
				{
105
					$this->dbuser = $dbuser;
0 ignored issues
show
Documentation Bug introduced by
The property $dbuser was declared of type boolean, but $dbuser is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
106
					$this->dbpassword = $dbpassword;
0 ignored issues
show
Documentation Bug introduced by
The property $dbpassword was declared of type boolean, but $dbpassword is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
107
					$this->dbhost = $dbhost;
108
					$this->dbport = $dbport;
0 ignored issues
show
Documentation Bug introduced by
It seems like $dbport can also be of type integer. However, the property $dbport is declared as type boolean. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
109
					$return_val = true;
110
111
					$this->conn_queries = 0;
112
				}
113
			}
114
115
			return $return_val;
116
		}
117
118
		/**********************************************************************
119
		*  Try to select a mySQL database
120
		*/
121
122
		function select($dbname = '', $encoding = '')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
123
		{
124
			global $ezsql_mysqli_str; $return_val = false;
125
126
			// Must have a database name
127
			if ( ! $dbname)
128
			{
129
				$this->register_error($ezsql_mysqli_str[3].' in '.__FILE__.' on line '.__LINE__);
130
				$this->show_errors ? trigger_error($ezsql_mysqli_str[3], E_USER_WARNING) : null;
131
			}
132
133
			// Must have an active database connection
134
			else if ( ! $this->dbh)
135
			{
136
				$this->register_error($ezsql_mysqli_str[4].' in '.__FILE__.' on line '.__LINE__);
137
				$this->show_errors ? trigger_error($ezsql_mysqli_str[4], E_USER_WARNING) : null;
138
			}
139
140
			// Try to connect to the database
141
			else if ( ! @$this->dbh->select_db($dbname))
142
			{
143
				// Try to get error supplied by mysql if not use our own
144
				if ( ! $str = @$this->dbh->error)
145
					  $str = $ezsql_mysqli_str[5];
146
147
				$this->register_error($str.' in '.__FILE__.' on line '.__LINE__);
148
				$this->show_errors ? trigger_error($str, E_USER_WARNING) : null;
149
			}
150
			else
151
			{
152
				$this->dbname = $dbname;
0 ignored issues
show
Documentation Bug introduced by
The property $dbname was declared of type boolean, but $dbname is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
153
				if ($encoding != '')
154
				{
155
					$encoding = strtolower(str_replace("-", "", $encoding));
156
					$charsets = array();
157
					$result = $this->dbh->query("SHOW CHARACTER SET");
158
					while ($row = $result->fetch_array(MYSQLI_ASSOC))
159
					{
160
						$charsets[] = $row["Charset"];
161
					}
162
					if (in_array($encoding, $charsets)) {
163
						$this->dbh->set_charset($encoding);
164
					}
165
				}
166
				
167
				$return_val = true;
168
			}
169
170
			return $return_val;
171
		}
172
173
		/**********************************************************************
174
		*  Format a mySQL string correctly for safe mySQL insert
175
		*  (no mater if magic quotes are on or not)
176
		*/
177
178
		function escape($str)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
179
		{
180
			// If there is no existing database connection then try to connect
181
			if ( ! isset($this->dbh) || ! $this->dbh )
182
			{
183
				$this->connect($this->dbuser, $this->dbpassword, $this->dbhost, $this->dbport);
0 ignored issues
show
Documentation introduced by
$this->dbuser is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->dbpassword is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->dbhost is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
184
				$this->select($this->dbname, $this->encoding);
0 ignored issues
show
Documentation introduced by
$this->dbname is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->encoding is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
185
			}
186
                        
187
						if ( get_magic_quotes_gpc() ) {
188
				$str = stripslashes($str);
189
						}                        
190
191
			return $this->dbh->escape_string($str);
192
		}
193
194
		/**********************************************************************
195
		*  Return mySQL specific system date syntax
196
		*  i.e. Oracle: SYSDATE Mysql: NOW()
197
		*/
198
199
		function sysdate()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
200
		{
201
			return 'NOW()';
202
		}
203
204
		/**********************************************************************
205
		*  Perform mySQL query and try to determine result value
206
		*/
207
208
		function query($query)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
209
		{
210
211
			// This keeps the connection alive for very long running scripts
212
			if ($this->count(false) >= 500)
213
			{
214
				$this->disconnect();
215
				$this->quick_connect($this->dbuser, $this->dbpassword, $this->dbname, $this->dbhost, $this->dbport, $this->encoding);
0 ignored issues
show
Documentation introduced by
$this->dbuser is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->dbpassword is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->dbname is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->dbhost is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->dbport is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->encoding is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
216
			}
217
218
			// Initialise return
219
			$return_val = 0;
0 ignored issues
show
Unused Code introduced by
$return_val is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
220
221
			// Flush cached values..
222
			$this->flush();
223
224
			// For reg expressions
225
			$query = trim($query);
226
227
			// Log how the function was called
228
			$this->func_call = "\$db->query(\"$query\")";
0 ignored issues
show
Bug introduced by
The property func_call does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
229
230
			// Keep track of the last query for debug..
231
			$this->last_query = $query;
232
233
			// Count how many queries there have been
234
			$this->count(true, true);
235
			
236
			// Start timer
237
			$this->timer_start($this->num_queries);
238
239
			// Use core file cache function
240
			if ($cache = $this->get_cache($query))
241
			{
242
				// Keep tack of how long all queries have taken
243
				$this->timer_update_global($this->num_queries);
244
245
				// Trace all queries
246
				if ($this->use_trace_log)
247
				{
248
					$this->trace_log[] = $this->debug(false);
249
				}
250
				
251
				return $cache;
252
			}
253
254
			// If there is no existing database connection then try to connect
255
			if ( ! isset($this->dbh) || ! $this->dbh)
256
			{
257
				$this->connect($this->dbuser, $this->dbpassword, $this->dbhost, $this->dbport);
0 ignored issues
show
Documentation introduced by
$this->dbuser is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->dbpassword is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->dbhost is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
258
				$this->select($this->dbname, $this->encoding);
0 ignored issues
show
Documentation introduced by
$this->dbname is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->encoding is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
259
				// No existing connection at this point means the server is unreachable
260
				if ( ! isset($this->dbh) || ! $this->dbh || $this->dbh->connect_errno)
261
					return false;
262
			}
263
264
			// Perform the query via std mysql_query function..
265
			$this->result = @$this->dbh->query($query);
0 ignored issues
show
Bug introduced by
The property result does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
266
267
			// If there is an error then take note of it..
268
			if ($str = @$this->dbh->error)
269
			{
270
				$this->register_error($str);
271
				$this->show_errors ? trigger_error($str, E_USER_WARNING) : null;
272
				return false;
273
			}
274
275
			// Query was a Data Manipulation Query (insert, delete, update, replace, ...)
276
			if ( ! is_object($this->result))
277
			{
278
				$is_insert = true;
279
				$this->rows_affected = @$this->dbh->affected_rows;
280
281
				// Take note of the insert_id
282
				if (preg_match("/^(insert|replace)\s+/i", $query))
283
				{
284
					$this->insert_id = @$this->dbh->insert_id;
0 ignored issues
show
Bug introduced by
The property insert_id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
285
				}
286
287
				// Return number fo rows affected
288
				$return_val = $this->rows_affected;
289
			}
290
			// Query was a Data Query Query (select, show, ...)
291
			else
292
			{
293
				$is_insert = false;
294
295
				// Take note of column info
296
				$i = 0;
297
				while ($i < @$this->result->field_count)
298
				{
299
					$this->col_info[$i] = @$this->result->fetch_field();
300
					$i++;
301
				}
302
303
				// Store Query Results
304
				$num_rows = 0;
305
				while ($row = @$this->result->fetch_object())
306
				{
307
					// Store relults as an objects within main array
308
					$this->last_result[$num_rows] = $row;
0 ignored issues
show
Bug introduced by
The property last_result does not seem to exist. Did you mean result?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
309
					$num_rows++;
310
				}
311
312
				@$this->result->free_result();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

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...
313
314
				// Log number of rows the query returned
315
				$this->num_rows = $num_rows;
0 ignored issues
show
Bug introduced by
The property num_rows does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
316
317
				// Return number of rows selected
318
				$return_val = $this->num_rows;
319
			}
320
321
			// disk caching of queries
322
			$this->store_cache($query, $is_insert);
323
324
			// If debug ALL queries
325
			$this->trace || $this->debug_all ? $this->debug() : null;
326
327
			// Keep tack of how long all queries have taken
328
			$this->timer_update_global($this->num_queries);
329
330
			// Trace all queries
331
			if ($this->use_trace_log)
332
			{
333
				$this->trace_log[] = $this->debug(false);
334
			}
335
336
			return $return_val;
337
338
		}
339
340
		/**********************************************************************
341
		 * Variables
342
		 */
343
		 private $s_query = "";
344
		 
345
		 private $s_params;
346
		/**********************************************************************
347
		*  set query
348
		*/
349
		function set_query($query)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
350
		{
351
			$this->s_query = $query;
352
			$this->s_params = array();
353
		}
354
355
		/**********************************************************************
356
		*  Special query to escape all parameters
357
		*/
358
		function bind_param($parameter, $value)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
359
		{
360
			$value = $this->escape($value);
361
			$this->s_params[$parameter] = $value;
362
			return 1;
363
		}
364
365
		/**********************************************************************
366
		*  Special query to escape all parameters
367
		*/
368
		function execute()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
369
		{
370
			if ($this->s_query != '')
371
			{
372
				$query = $this->s_query;
373
374
				if ( ! empty($this->s_params))
375
				{
376
					foreach ($this->s_params as $param => $value)
377
					{
378
						$count = 0;
379
						$query = str_replace($param, $value, $query, $count);
380
						if ($count == 0)
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $count of type integer|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
381
						{
382
							$str = $query.' no parameter was changed';
383
							$this->register_error($str.' in '.__FILE__.' on line '.__LINE__);
384
							$this->show_errors ? trigger_error($str, E_USER_WARNING) : null;
385
						}
386
					}
387
				}
388
389
				$this->s_query = "";
390
				$this->s_params = array();
391
392
				return $this->query($query);
393
			} else
394
			{
395
				return NULL;
396
			}
397
		}
398
399
		/**********************************************************************
400
		*  Close the active mySQLi connection
401
		*/
402
403
		function disconnect()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
404
		{
405
			$this->conn_queries = 0;
406
			@$this->dbh->close();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

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...
407
		}
408
409
	}
410