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

  • Home
  • SEARCH
  • 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 7827823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:03:39+00:00 2026-06-02T10:03:39+00:00

I have the following piece of code: $clicks = $statement->prepare($query); $offers->bindValue(1, $id, PDO::PARAM_INT); $clicks->execute();

  • 0

I have the following piece of code:

$clicks = $statement->prepare($query);
$offers->bindValue(1, $id, PDO::PARAM_INT);
$clicks->execute();
$results = $clicks->fetchAll();
  • The Query works fine
  • The binding works fine

What actually makes me wonder, why I have to first execute() the query to can call fetchAll().
I’ve come to this solution/assumption since, execute() only returns true/false and without calling execute(), fetchAll() will not return anything.
Is this the normal way of doing that?

I’ve been working with PDO before, long time ago, so I can’t quite remember how to deal with it properly.

Thank you very much

(I use PHP5.3, the above used code is PDO/PDOStatement)

  • 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-02T10:03:42+00:00Added an answer on June 2, 2026 at 10:03 am

    Well, SELECT * FROM myTable is just a piece of text and you have to send it to the server first, which parses it etc, before you can fetchAll(). The reason that fetchAll doesn’t automatically execute() is that fetchAll can be called twice, and you don’t want to execute the query twice if you only have to do it once 🙂

    It’s also related to parameter binding etc. Parameters can change but you might still want to use the fetch functions on the original parameter value.

    It’s a design thing, which makes programming with PDO a lot easier. It just requires 1 more line of code 🙂

    You could probably create a wrapper and make fetchAll() do both the execution and the fetch, but you’re definitely going to run into trouble.

    edit:
    Another reason is that execute() actually takes an optional array of parameters which allows you to bind parameters. $stmt -> execute(array($id)); would allow you to skip the bindValue calls.

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

Sidebar

Related Questions

I have following piece of code: It compiles without problems under gcc-3.4, gcc-4.3, intel
I have following piece of code : public Hashmap<String,String> tempmap = new HashMap<String,String>(); and
I have the following piece of code taken from the PHP manual on the
I have the following piece of code in C++. int arr[] = {1, 2,
I have the following piece of code: // setup the AJAX request var pageRequest
I have the following piece of code from a book. There is this function
I have the following piece of code: for i := 0 to FControlList.Count -
I have the following piece of code: class Foo { public Foo() { Bar
I have the following piece of code: $(document).ready(initialize); function initialize() { $('#btnPoint').css('width', $('#btnPoint').width()); }
I have the following piece of code. <?php $agentId = LTH001; echo && .

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.