My general rule of thumb is to use it for everything because I am worried that another developer will get into the code and change my static variable to dynamic and will not use a cfqueryparam. If I use cfqueryparam’s everywhere and the developer changes a static variable to dynamic the cfqueryparam will already be in place.
Randy
To expand slightly on Randy's comment, the rule of thumb is to *always* use cfqueryparam unless and until you've proven that the query in question is causing a performance problem. Trying to optimize before there's a problem is about as efficient as the US Congress.
To expand slightly on Randy's comment, the rule of thumb is to *always* use cfqueryparam unless and until you've proven that the query in question is causing a performance problem. Trying to optimize before there's a problem is about as efficient as the US Congress.
I'm sorry, I didn't mention I'm using mysql 5.5 here. I'm seeing no performance gain with preparedstatement vs no preparedstatement under heavy load. It is possible another database or driver would act differently. And maybe it's possible to perform different when the data access is more random / not cached. Perhaps a query that has 5 joins, subqueries, sorting, having, limit, group by and 10 different indexes to choose from will have more of a performance hit on deciding the query plan. But if you need that query to be faster, you'd probably optimize it so that query doesn't need joins, subqueries, sorting, etc. It seems like preparedstatement is more likely to help queries that are too complex. I had tried to have a simple query with 8 parameters to determine if more parameters effected performance, but it only slows down "new query()" CFC approach - The java versions are all fast. If I did another test with more elaborate SQL, I may find different results. I do want to use cfqueryparam exclusively in the future regardless. Adam, I didn't understand what preparedstatement was when I built most of my queries year ago, and I've yet to convert them to cfqueryparam, but I'm looking at doing that now. I'm sure I'll squeeze a little performance out of this, but I thought others might be interested in knowing that a larger application that doesn't use it at all can still be incredibly fast.