1

I was trying to return a set of objects.

But this code gives me the following error:

Catchable fatal error: Object of class User could not be converted to string in ...

 public function fetchObject($psClassname ="",$paParams =array()){
            $lrResource = $this->mrQueryResource;
            $liResult = null; 
            while($row = mysql_fetch_object($lrResource,$psClassname,$paParams)){
                $liResult .= $row;     <-this line produces the error
            }
            return $liResult;
         }

2 Answers 2

4

In your code $row is a an object (you've used mysql_fetch_object), and the .= operator tries to build a string, concatenating $liResult and $row. I believe this behaviour only works if your object implements a toString method

You could return an array of rows using this code:

public function fetchObject($psClassname ="",$paParams =array()){
        $lrResource = $this->mrQueryResource;
        $liResult = array();
        while($row = mysql_fetch_object($lrResource,$psClassname,$paParams)){
                $liResult[] = $row;
        }
        return $liResult;
}
Sign up to request clarification or add additional context in comments.

Comments

0

That's because you are trying to convert $row to a string (the .= assumes a string is given on the right hand side)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.