3
I would like to know the difference in safety level between the two code snippets below:
// TRECHO 1
<?php
$calories = 150;
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < ? AND colour = ?');
$sth->bindParam(1, $calories, PDO::PARAM_INT);
$sth->bindParam(2, $colour, PDO::PARAM_STR, 12);
$sth->execute();
?>
// TRECHO 2
<?php
$calories = 150;
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < ? AND colour = ?');
$sth->execute(array($calories,$colour));
?>
In section 1, the bindParam()
, in 2 the parameters are passed directly in the execute, but also the prepare()
.
If I type, and pass a parameter that does not obey it, it either converts and executes it or it does not perform?
– Miguel Neto
If you type a string as boolean will work, you will only have a problem in the case I quoted in the question, Prepared statements are emulated by default. @Miguelneto
– rray