www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Does a prepared statement get cached?

  1. #1
    Join Date
    Dec 2006
    Posts
    48

    resolved [RESOLVED] Does a prepared statement get cached?

    Hey everyone, quick question. Says the PHP manual,
    $stmt = $mysqli->prepare("SELECT * FROM test WHERE id = ?");
    this will make the database prepare itself to run this query; find out the best way to run it, how to structure the results, etc. If I use this same $stmt later, then all that work is still saved, yay!

    My question, however, is what if I don't use the $stmt variable? If I call $mysql->prepare with the same exact string, will it see that its the same as before, and use the earlier preparations? Or do I absolutely have to save the $stmt variable and use it again, to get the nice speed boost?

    - Evan

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,518
    As far as I know, a new "prepare" would be handled separately and without knowledge of the prior query. I cannot claim to be 100% positive about that, but pretty darned close.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Dec 2006
    Posts
    48
    Okay cool, thanks for the quick response.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles