PHP - Does PDO quote safe from SQL Injection?

前端 未结 3 1443
北恋
北恋 2020-12-16 05:01
$id  = trim((int)$_GET[\'id\']);
$sql = \'SELECT * FROM users WHERE id = \' . $db->quote($id) . \' LIMIT 1\';
$run = $db->query($sql)->fetch();
3条回答
  •  借酒劲吻你
    2020-12-16 05:27

    Technically - yes.

    However, it means that you are formatting your values manually. And manual formatting is always worse than prepared statements, as it makes code bloated and prone to silly mistakes and confusions.

    The main problem with manual formatting - it is detachable. Means it can be performed somewhere far away from the actual query execution. Where it can be forgotten, omitted, confused and such.

提交回复
热议问题