PHP PDO操作MySQL时,如何避免SQL注入风险?
- 内容介绍
- 文章标签
- 相关推荐
本文共计89个文字,预计阅读时间需要1分钟。
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);
<?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));
本文共计89个文字,预计阅读时间需要1分钟。
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);
<?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));

