标签:employees name comm 表达 string pdo 用户 ash pre
防止SQL注入,我们需要注意以下几个要点:
到底我们能做什么去防止sql注入呢?
1、通过使用预编译语句(prepared statements)
使用PDO对象(对于任何数据库驱动都好用)
$stmt = $pdo->prepare(‘SELECT * FROM employees WHERE name = :name‘);
$stmt->execute(array(‘name‘ => $name));
foreach ($stmt as $row) {
// do something with $row
}
2、参数化查询(parameterized queries)
使用MySqli
$stmt = $dbConnection->prepare(‘SELECT * FROM employees WHERE name = ?‘);
$stmt->bind_param(‘s‘, $name);
$stmt->execute();
标签:employees name comm 表达 string pdo 用户 ash pre
原文地址:https://www.cnblogs.com/chenhaoyu/p/8758888.html