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();
本文通过一个简单的PHP示例展示了如何利用SQL注入获取数据库全部信息,并介绍了使用占位符的方法来有效防止此类安全威胁。
26万+

被折叠的 条评论
为什么被折叠?



