Hi i've came across several threads but couldnt really find the answers. there are quite a few doubts i have regarding mysql injections. pardon me if the questions seem too easy or stupid. here are some examples.
1. Are queries comparatively safer from sql injections if the parameters are bounded by quotes?
if i try to add something like $id = ' id; DROP table ', the query without the quotes around the variable would have been vulnerable. the query with the quotes would be harder to break with something like $id = ' x'; DROP table '. But since $id has already been sanitised. it wouldnt happen right?PHP Code:$id = mysql_real_escape_string($_POST['id']);
$query = " SELECT names FROM table WHERE id = '$id' "; /* as compared to */
$query = " SELECT names FROM table WHERE id = $id ";
2. if i use mysql_query($query), sql injection is greatly reduced?
Using the previous example if i were to try to do an injection, it wouldnt be possible right? Since mysql_query only allows a single query and the DROP table part i injected wouldnt be sent to the server?
3. Are queries with no user input vulnerable to SQL injections?
For example,
------------------------------------------PHP Code:$query = " SELECT names FROM table WHERE id = '1' ";
PDO Questions.
4. Are PDO statements vulnerable?
ifPHP Code:try {
$dbh = new PDO("mysql:host=localhost;dbname=database", "user", "password");}
catch(PDOException $e)
{Header("Location:/error.php");}
$id = mysql_real_escape_string($_POST['id']);
$query = $dbh->prepare (' SELECT email FROM table WHERE id = :id ');
$query->bindParam( ':id' , $id );
$query->execute();
. Is this possible to execute in a PDO statement? i have tried it but it doesnt work. so im not sure whether it is possible. if it was possible, with reference to question 1, would it be safer to bound the parameters by quotes like thisPHP Code:$id = ' 1; INSERT INTO memberslist (email, ID) VALUES (hi, 1) '
5. Is there a need to catch exceptions from pdo statements since if there was a failure to connect to the database in the first place, the first exception would have been caught and redirected to the error page?PHP Code:$query = $dbh->prepare (' SELECT email FROM table WHERE id = ":id" ');
6. Is it feasible or productive if i use PDO statements together with normal queries like mysql_query(). Since i would have to connect again using mysql_connect(). or is it more productive if i only used one type of method?
Sorry if its abit long. Thank you very much for your time.


LinkBack URL
About LinkBacks
Reply With Quote


