I am confuse between these two functions Bindvalue()
and BindParam()
- I read on php.net it does not escape
%
and_
, so be careful when usingLIKE
. So i thinkBindValue()
is not used when we are using LIKE query. - when we using
LIKE
queryBindParam()
is used. Because as i know BindParam can escape these%
and_
. BindValue()
doesn't gives protection against sql injection. I am not sure about this, is it true?
friends tell what i mention in these 3 points is right or wrong. i am beginner in PDO so please explain it clearly ..
Well, you took it all wrong.
Bindvalue()
andBindParam()
are equal in either way except for the argument type.Both of them do not escape % and _, which doesn't matter too much. Such escaping affects only reliability of the returned results, not whatever "injections".
There should be no difference in how values are escaped or not escaped.
bindParam
differs frombindValue
in that it references the variable, binding the value only when you execute the statement.bindValue
takes the value immediately. To illustrate:The above executes like
SELECT * FROM table WHERE foo = 'foo'
;The above executes like
SELECT * FROM table WHERE foo = 'bar'
.It's true that neither cares about
_
or%
as special characters, because generally speaking they aren't special characters as far as the syntax is concerned, and the database driver is not able to analyze the context to figure out whether you mean%
to be a wildcard or the actual character "%" in the context of aLIKE
query.Both protect against SQL injection.