views:

85

answers:

3

I know its supposed to improve performance and clean strings, but lets say there are no variables?

Might just be a

SELECT COUNT( `column` ) AS count FROM `table`
  1. Should that be prepared?
  2. Is there any case that a SELECT statement should not be prepared?
A: 

Depends on how frequently you will perform this query with different parameters. If you will execute this query for different "column"s and "table"s very frequently, then it makes sense to make it a prepared query. Otherwise, you don't need to do it a prepared query.

jaxvy
Not all database drivers let you bind column or table names in prepared statements. I'm not sure if MySQLi does or not.
R. Bemrose
+6  A: 

As a general rule, you should prepare statements that take variables from somewhere else. Usually this includes INSERT and UPDATE statements, SELECTs and DELETEs with WHERE clauses, and stored procedure calls with arguments.

R. Bemrose
+3  A: 

A general rule: If the query contains user input, it should be prepared. Otherwise, you don't have to. Your example doesn't need to be prepared.

ZZ Coder