Solved

Does PDO::PARAM_STR filters the input from user?

Posted on 2014-10-20
4
243 Views
Last Modified: 2014-10-20
Dear experts,

The I was using the PDO function from php with prepare statements.

I have an input string like this: 'UPDATE tbl_1 Set city = :city and id = :id';

$city = 'Mongo';
$id = 3;
I've also have my bindParam() like this: bindParam(':city', $city, PDO::PARAM_STR);
and bindParam(':id', $id, PDO::PARAM_INT);

somehow I changed the PDO::PARAM_STR into PDO::PARAM_INT for bindParam(':city', $city, PDO::PARAM_STR) and the result from $city still works. I am wondering what does the PDO::PARAM_STR or the PDO::PARAM_INT do because it is not filtering out the input for me.  Thanks.
0
Comment
Question by:Kinderly Wade
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40393258
If you pass it a string and tell it it's a number then it will know it's string and quote it anyway.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40393393
Quoted numbers do no harm.  Unquoted strings are not so good.  But PDO does not really do "quoting" like we do when we use other MySQL extensions.  And PDO does nothing to filter input - that is the programmer's responsibility.  Accept Only Known Good Values.  All PDO does is prevent bad query strings from causing the MySQL engine to bark or belch out the wrong data.

The general way to handle PDO parameterization is given in this article.  See PDO - Prepare a Query
http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
 

Author Closing Comment

by:Kinderly Wade
ID: 40393434
Thanks Ray. You nailed the question right on the spot.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40393460
Thanks for the points -- it's a very worthwhile question, ~Ray
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question