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 7753811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:08:49+00:00 2026-06-01T12:08:49+00:00

I noticed PDO::FETCH_INTO fetch mode doesn’t work inside PDOStatement::fetch() but in the manual it

  • 0

I noticed PDO::FETCH_INTO fetch mode doesn’t work inside PDOStatement::fetch() but in the manual it says you can use PDO::FETCH_INTO with PDOStatement::fetch().

I was trying to do:
$query->fetch( PDO::FETCH_INTO, $user );

This returns: PDOStatement::fetch() expects parameter 2 to be long, object given

Wouldn’t that mean the manual is kind of misleading? And what would be the proper way of using PDO::FETCH_INTO in this case?

  • 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-01T12:08:51+00:00Added an answer on June 1, 2026 at 12:08 pm

    Try this way:

    $stmt->setFetchMode(PDO::FETCH_INTO, $user);
    $user = $stmt->fetch();
    

    UPDATE:

    If you have private/protected properties with public setters (which is recommended) instead of public properties, use FETCH_CLASS instead:

    class User {
        protected $username;
    
        public setUsername($username) {
            $this->username = $username;
        }
    ...
    }
    ...
    $stmt->setFetchMode(PDO::FETCH_CLASS, 'User');
    $user = $stmt->fetch();
    

    UPDATE 2:

    Using PDO::FETCH_CLASS, you don’t even need the setter (EDIT: don’t need the setter for PDO, which is good for id fields):

    class User {
        protected $username;
    ...
    }
    ...
    $stmt->setFetchMode(PDO::FETCH_CLASS, 'User');
    $user = $stmt->fetch();
    

    UPDATE 3: see full example here: http://pastebin.com/LneAj0xn

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

Sidebar

Related Questions

UPDATE 1: I've just noticed PDO::MYSQL_ATTR_FOUND_ROWS in the manual, but I'm not sure how
I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but
Noticed an interesting GUI based setting in MacVim, that seems useful but I can't
I noticed the other day that I cannot bind variables when using PDO with
Recently I was going through a blog and noticed some points about using PDO
I am switching from plain mysql in php to PDO and I have noticed
I noticed that i can set a return type on a function to 'Void'
I noticed on the twitter docs for grid system it says the default grid
I noticed that when I do something like this (with jQuery, but I don't
I noticed that all the Facebook applications that running inside an iframe hiding their

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.