Possible Duplicate:
Php PDO::bindParam data types.. how does it work?
Say for example, that I have the following prepared statement:
$sth = $dbh->prepare('SELECT `name` FROM `user` WHERE `user_id` = :user_id');
I could bind the user_id parameter like so:
$sth->bindValue(':user_id', $user_id_value);
And I'd still be safe from SQL injections.
However, bindValue() also an optional parameter called data_type, which allows you to set an explicit data type. Example:
$sth->bindValue(':user_id', $user_id_value, PDO::PARAM_INT);
That allows me to state that user_id will be an integer.
My question is: Why use the data_type parameter in bindValue if you're safe against SQL injections with or without it? Is it there to force data integrity? If you're validating your data beforehand, do you need to worry about using it? Are there any other benefits to using it that I haven't thought about?