Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I prepare all queries even if they will only be executed once?

Using PHP's PDO class, does preparing queries cause a (slight even) performance hit that isn't made up if you only execute the query once per connection? I'm making a small data access layer and I'm wondering if it's okay to blindly prepare all queries, or if I should only prepare queries that will be reused.

like image 282
Parris Varney Avatar asked Oct 17 '25 09:10

Parris Varney


1 Answers

Prepared statements arent only for reused queries. They should be used for all queries that have untrusted data, making sure to bind the untrusted data. This eliminates SQL injection opportunities.

http://www.php.net/manual/en/pdo.prepared-statements.php

like image 111
Galen Avatar answered Oct 20 '25 00:10

Galen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!