Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8693955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:40:00+00:00 2026-06-13T00:40:00+00:00

I am trying to figure out how to fetch from PDO into my custom

  • 0

I am trying to figure out how to fetch from PDO into my custom class, and in general the PDO-to-object API, and am finding the lack of decent documentation frustrating. Most of the options are only documented as an option, while the examples all use fetching into arrays.
So, can someone explain how these are used:

  • PDO::FETCH_OBJ
  • PDO::FETCH_CLASS
  • PDO::FETCH_CLASSTYPE
  • PDO::FETCH_INTO
  • PDO::FETCH_LAZY
  • PDOStatement::fetch
  • PDOStatement::fetchObject
  • PDOStatement::setFetchMode

If possible, I would like a general explanation how each function/constant is used for fetching objects, or what the differences are, as well as a specific answer to how do I fetch into my class, e.g. into:

class MyRow {
  public $col1, $col2;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:40:01+00:00Added an answer on June 13, 2026 at 12:40 am

    Here is what I managed to figure out:

    Constants

    • PDO::FETCH_OBJ
      Is used to fetch into a new instance of an unnamed (“anonymous”) object

    • PDO::FETCH_CLASS
      Is used to fetch into a new instance of an existing class (the column names should match existing properties, or __set should be used to accept all properties). The constructor of the class will be called after the properties are set.

    • PDO::FETCH_CLASSTYPE
      Used with FETCH_CLASS (bitwise OR), the name of the class to create an instance of is in the first column, instead of supplied to the function.

    • PDO::FETCH_INTO
      Is used with the same type of class as FETCH_CLASS (must handle all columns as property names), but updates an existing object as opposed to creating a new one.

    • PDO::FETCH_LAZY
      I don’t know what this does.

    Functions

    • PDOStatement::fetch
      The regular get-a-row command. I don’t know how to use this with FETCH_CLASS or FETCH_INTO since there does not be any way to pass the class name/instance.

    • PDOStatement::fetchObject
      A way to do FETCH_CLASS or FETCH_INTO, including passing constructor args. With no args is a shorthand for FETCH_OBJ.

    • PDOStatement::setFetchMode
      A way to set the default fetch mode, so that PDOStatment::fetch can be called without args.


    That is the best I managed to figure out. I hope it helps someone else (I needed the fetchObject method)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create an object from an HQL query, but just can't figure out
Trying to figure out why File Attachment isn't showing on a custom content type.
I am trying to figure out informative data patterns from large volume transactional data.
I'm trying to make the jump from procedural code to the PDO class, and
I'm trying to figure out a way to populate an XML object more dynamically
I'm trying to figure out how to skip printing a row from a MySQL
HI all, I am trying to figure out how to put this into words
I am trying to figure out how to put a mysql query result into
I've been trying to figure out the best way to return an order from
Trying to figure out how I can do this properly. The print_r looks like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.