SQL注入

来源:互联网 发布:上海互联网软件集团 编辑:程序博客网 时间:2024/06/07 15:36
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();

                                             
0 0
原创粉丝点击