Solved

Does PDO::PARAM_STR filters the input from user?

Posted on 2014-10-20
4
240 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

832 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