从rails的活动记录查询
guide on sql injection
This code is highly preferable:
Client.where(“orders_count = ?”,params[:orders])
到这段代码:Client.where(“orders_count = #{params[:orders]}”)
我的问题是我想使用带有通配符的LIKE子句.我的旧查询看起来像这样 –
User.where("first_name LIKE '%#{first_name}%'")哪个容易受到sql注入,但如果我这样做:
User.where("first_name LIKE '%?%'",first_name)SELECT "users".* FROM "users" WHERE (first_name LIKE '%'michael'%')由于额外的单引号无效.