您的位置:首页 > 数据库

SQL注入

2015-10-21 20:28 344 查看
public function actionIndex(){
$id='8 or 1=1 ';
$sql="select * from test where id=$id";
$res=Test::findBySql($sql)->all();
print_r($res);
}
or 1=1永远为真,所以,用户可能查出数据库的所有资料。
为防止SQL注入,方法一:使用占位符;
$sql="select * from test where id=:id";
$res=Test::findBySql($sql,array(':id'=>$id))->all();

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: