How does php pdo's prepared statements prevent sql injection
Rather than being annoying about nitpicking this question, I'll give you the answer to the real question: prepare
ing a query essentially runs mysql_real_esape_string
or some equivalent on each token (represented by a question mark or :value
). This makes it easier to make sure all variable data is properly escaped. This does not prevent all security problems (for example, %
and _
are not escaped, which can impact LIKE
clauses).
What are other pros/cons of using PDO?
As far as I know there are no cons to using PDO
. I suppose a con is that it does not support all known DBs .. there are limited drivers, but this is only a con if you want to use PDO for a DB that it cannot support. Pros? Well you get a lot of flexibility out of PDO, especially if you create a wrapper for it (just in case you needed to switch DBAs), and since it's compiled C it's supposedly faster than using other php functions (see below). It also saves you from having to write your own methods to prepare queries, etc.
Does using PDO reduce efficiency
Reduce efficiency compared to what? What kind of efficiency? Programming efficiency, or execution speed? As I understand it, PDO is compiled so using it should actually be faster than creating your own DB wrapper to prepare queries and such. If this is really a concern, you can benchmark the difference, but I suggest you look elsewhere for slowdowns first.