Kerry Jones
Kerry Jones

Reputation: 21838

MySQLi - Should every statement be prepared?

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?

Upvotes: 2

Views: 275

Answers (2)

ZZ Coder
ZZ Coder

Reputation: 75456

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.

Upvotes: 4

Powerlord
Powerlord

Reputation: 88796

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.

Upvotes: 7

Related Questions