3

I am trying to use FETCH_LAZY. I can use a while loop whilst setting $row equal to $query->fetch(). The problem is that fetchAll does not work when the fetchMode is FETCH_LAZY.


How can I return an array of PDO Objects?

Thanks.

1
  • 1
    Show us some code that you've tried? Commented Feb 12, 2017 at 4:09

1 Answer 1

3

Due to the very nature of FETCH_LAZY, you cannot use fetchAll with this mode. It can be used with fetch() only.

It seems that you are simply confusing this mode with FETCH_OBJ which will give you an array of objects you need

$array = $stmt->fetchAll(PDO::FETCH_OBJ);

Also note that beside creating stdObj instances you can make fetchAll to return an array of objects of any other class as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.