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();