You have to check if the query was successful. See
PHP: mysqli_result::fetch_object - Manual[
^].
The second error informs you that the
$res
variable has not been defined when used in the
return
statement. It has been defined in the loop but is out of scope (not seen outside the loop). So you have to define it first in the scope of the function.
So use something like (untested):
public function sel($con,$t1)
{
$res = array();
$sql="select * from $t1";
$q=$con->query($sql);
if ($q)
{
while ($fet=$q->fetch_object())
{
$res[]=$fet;
}
}
return $res;
}
Note also that
$con
must be a valid connection (check it before calling the function).