PHP中通过参数化查询防止sql注入,有两种方法,一是通过pdo,一是通过MysqLi
使用 PDO:
/**
* PHP中通过参数化查询防止sql注入
*
* @param
* @arrange 512-笔记网: www.512Pic.com
**/
$stmt = $pdo->prepare('SELECT * FROM employees WHERE name = :name');
$stmt->execute(array(':name' => $name));
foreach ($stmt as $row) {
// do something with $row
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
使用 MysqLi
/**
* PHP中通过参数化查询防止sql注入
*
* @param
* @arrange 512-笔记网: www.512Pic.com
**/
$stmt = $dbConnection->prepare('SELECT * FROM employees WHERE name = ?');
$stmt->bind_param('s',$name);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
// do something with $row
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/528346.html