Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any security benefits to using PDO::query vs. mysql_query?

Tags:

php

pdo

I'm looking to refactor some legacy PHP code, and I know that PDO is more secure with the addition of prepared statements and such, but I am wondering if there are any security benefits of using the PDO::query() method vs. the mysql_query() method. Are there?

like image 442
GSto Avatar asked Dec 30 '25 11:12

GSto


1 Answers

Short of a bug in PDO or mysql_*, the security issues with database queries are dependent on the query being ran, not what is used to connect to the database.

If you create an insecure query with userdata and execute it with PDO::query(), it is just as insecure as it is with mysql_query(). Likewise, if you have a secure query, running it with PDO::query() is effectively the same as with mysql_query().

like image 105
Brad Avatar answered Jan 02 '26 00:01

Brad



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!