Page 1 of 1

Passing mysqli result to a class

Posted: Sat Jan 22, 2005 5:52 am
by nqaul
Hi,

I need to pass the results of a query to a seperate class
but I keep getting an error saying that a mysqli object is
required.

Ex:

With a class like:

Code: Select all

class Test
{
  function Do_Stuff($results)
  {
    while ($row = mysqli_fetch_array($results)
      echo $rowї0];
  }
}
Assuming I've done the db con correctly and included
everything I need in a script like:

Code: Select all

$obj = new Test();
$res = mysqli_query($dbcon, $query);

obj->Do_Stuff($res);
When $res is passed to the Do_Stuff function I get the error:
"mysqli_fetch_array() expects parameter 1 to be mysqli, object
given in ....filename...."

but when I use the $res in the script its fine.

Can you not pass query result objects or is this loosing scope?

Thanks in advance
nqaul