Prepared statements add a significant amount of code…yet I keep hearing mentions of using them…what value is added by going from 1 line of code to about 6? Is this simply to protect against SQL injection?
php.net on prepared statements here
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Prepared statements offer excellent protection against SQL injection.
In addition to SQL injection protection, prepared statements offer reduced load on the database server when the same query is to executed multiple times, such as in an
INSERTloop. The statement is only compiled once by the RDBMS rather than needing to be compiled each time as it would in amysql_query()call.Different APIs require varying amounts of code to execute a prepared statement. I find that PDO can be a little less verbose than MySQLi, if for example your situation permits the use of implicit parameter binding inside the
execute()call. This only works, if all your params can be evaluated as strings though.