title: When *not* to use prepared statements?
body: <p>I'm re-engineering a PHP-driven web site which uses a minimal database. The original version used "pseudo-prepared-statements" (PHP functions which did quoting and parameter replacement) to prevent injection attacks and to separate database logic from page logic.</p>
  
  <p>It seemed natural to replace these ad-hoc functions with an object which uses PDO and real prepared statements, but after doing my reading on them, I'm not so sure. PDO still seems like a great idea, but one of the primary selling points of prepared statements is being able to reuse them… which I never will. Here's my setup:</p>
  
  <ul>
  <li>The statements are all trivially simple. Most are in the form <code>SELECT foo,bar FROM baz WHERE quux = ? ORDER BY bar LIMIT 1</code>. The most complex statement in the lot is simply three such selects joined together with <code>UNION ALL</code>s.</li>
  <li>Each page hit executes <em>at most</em> one statement and executes it only once.</li>
  <li>I'm in a hosted environment and therefore leery of slamming their servers by doing any "stress tests" personally.</li>
  </ul>
  
  <p>Given that using prepared statements will, at minimum, double the number of database round-trips I'm making, am I better off avoiding them? Can I use <code>PDO::MYSQL_ATTR_DIRECT_QUERY</code> to avoid the overhead of multiple database trips while retaining the benefit of parametrization and injection defense? Or do the binary calls used by the prepared statement API perform well enough compared to executing non-prepared queries that I shouldn't worry about it?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Thanks for all the good advice, folks. This is one where I wish I could mark more than one answer as "accepted" — lots of different perspectives. Ultimately, though, I have to give <a href="https://stackoverflow.com/questions/535464/when-not-to-use-prepared-statements/537834#537834">rick</a> his due… without his answer I would have blissfully gone off and done the completely Wrong Thing even after <em>following</em> everyone's advice. :-)</p>
  
  <p>Emulated prepared statements it is!</p>