Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP PDO Sanitize variables

Tags:

php

mysql

pdo

Im working with PDO for the first time and im wondering if the below looks safe, I've tried to read up on alternatives to mysql_real_escape and it seems like the 'prepare' method is sufficient enough security wise, can anyone clarify this for me? Still appears vulnerable...

$UID = $_GET['id'];

$sth = $conn->prepare("SELECT * FROM directory WHERE user_active != '' AND ID = :uid");
$sth->execute(array(':uid' => $UID));
like image 381
Liam Avatar asked Jun 13 '26 13:06

Liam


1 Answers

The prepare method is not only sufficient, it's preferred over mysql_real_escape().

Your code works, as $UID will be transmitted with a different protocol than the rest of the SQL statement. Since the database treats it differently, there's no need to escape.

like image 169
SomeKittens Avatar answered Jun 16 '26 04:06

SomeKittens



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!