I have been spotting the sentence PHP PDO's prepared statements prevents SQL injection
.
- How does php PDO's(PDO's prepared statements) prevent sql injection?
- What are other pros/cons of using PDO(PDO's prepared statements)?
- Does using PDO(PDO's prepared statements) reduce efficiency?
I have read this: Are PDO prepared statements sufficient to prevent SQL injection? But the data there is not completely clear.
Prepared statements are very useful against SQL injections, because parameter values, which are transmitted later using a different protocol, need not be correctly escaped. If the original statement template is not derived from external input, SQL injection cannot occur.
Also, calling PDO::prepare() and PDOStatement::execute() helps to prevent SQL injection attacks by eliminating the need to manually quote and escape the parameters.
Now to avoid this type of SQL injection, we need to sanitize the password input and username input using mysqli_real_escape_string() function. The mysqli_real_escape_string() function takes the special characters as they were as an input from the user and doesn't consider them as query usage.
Both MySQLi and PDO have their advantages: PDO will work on 12 different database systems, whereas MySQLi will only work with MySQL databases. So, if you have to switch your project to use another database, PDO makes the process easy. You only have to change the connection string and a few queries.
Well, at second glance your question looks more complex to be answered with just one link
How does php pdo's prepared statements prevent sql injection?
How can prepared statements protect from SQL injection attacks?
What are other pros/cons of using PDO?
Most interesting question.
A greatest PDO disadvantage is: it is peddled and propagated a silver bullet, another idol to worship.
While without understanding it will do no good at all, like any other tool.
PDO has some key features like
Does using PDO reduce efficiency?
Again, it is not PDO, but prepared statements that reduces efficiency. It depends on the network latency between the db server and your application but you may count it negligible for the most real world cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With