PHP使用PDO操作MySQL时,若忽视安全,是否仍面临SQL注入风险?
- 内容介绍
- 文章标签
- 相关推荐
本文共计63个文字,预计阅读时间需要1分钟。
phpPDO连接数据库并执行查询,设置字符集为UTF-8,准备SQL语句。
<?php dbh = new PDO("mysql:host=localhost; dbname=demo", "user", "pass"); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $dbh->exec("set names 'utf8'"); $sql="select * from test where name = ? and password = ?"; $stmt = $dbh->prepare($sql); $exeres = $stmt->execute(array($name, $pass));
本文共计63个文字,预计阅读时间需要1分钟。
phpPDO连接数据库并执行查询,设置字符集为UTF-8,准备SQL语句。
<?php dbh = new PDO("mysql:host=localhost; dbname=demo", "user", "pass"); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $dbh->exec("set names 'utf8'"); $sql="select * from test where name = ? and password = ?"; $stmt = $dbh->prepare($sql); $exeres = $stmt->execute(array($name, $pass));

