The following method does its job but keeps printing a warning also, im pretty new to OOP so i would like to know why exactly.
I have done some Googling and it seems likes its me mixing procedural with OOP which is giving the warning, well from the replies i have read elsewhere at least.
The code:
function __construct(){
global $connection;
$mysqli_result=$connection->query("select module from modules");
while($row=$mysqli_result->fetch_row()){
$this->whitelist[]=$row[0];
}
mysqli_free_result($row);
return;
}
The warning:
mysqli_free_result() expects parameter 1 to be mysqli_result, null given in.....
I would appreciate someone shedding some light on this if possible.
You are using
MySQLiin an object oriented fashion,and you cannot use the procedural functions with itincorrect, see edit. You would do:…instead.
Even if you were using the procedural approach, what you have done is incorrect because
fetch_row()returns an array, andmysqli_free_result()would expect the result resource – you would need to do:…but for your code, the first example is what you want.
EDIT
Actually, after testing, you can in fact use the second option as well. But still, the first option is the best fit for your code.