Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Does PDO::PARAM_STR filters the input from user?

Posted on 2014-10-20
4
Medium Priority
?
266 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

Expert Comment

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

916 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