$query = "SELECT * FROM table WHERE id='$id'";
which will negate the advantage of prepared statements by making data (probably user-supplied) part of the query!




Posted 04 October 2012 - 07:32 PM
$query = "SELECT * FROM table WHERE id='$id'";
Posted 04 October 2012 - 08:12 PM
CTphpnwb, on 04 October 2012 - 07:32 PM, said:
$query = "SELECT * FROM table WHERE id='$id'";
$query = "SELECT * FROM people WHERE id= ?"; $sth = $dbh->prepare($query); $sth->bindParam(1, $this->id,PDO::PARAM_INT); $sth->execute(); $result = $sth->fetch(PDO::FETCH_ASSOC); $dbh = NULL; return $result;
This post has been edited by adn258: 04 October 2012 - 08:18 PM
Posted 04 October 2012 - 08:26 PM
This post has been edited by CTphpnwb: 04 October 2012 - 08:30 PM
Posted 04 October 2012 - 08:35 PM
CTphpnwb, on 04 October 2012 - 08:26 PM, said:
This post has been edited by adn258: 04 October 2012 - 08:38 PM
Posted 04 October 2012 - 08:48 PM
Posted 04 October 2012 - 10:28 PM
CTphpnwb, on 04 October 2012 - 08:48 PM, said:
$query = "DELETE FROM comments WHERE ID=? AND poster=?;";
$stmt = $dbh->prepare($query);
$stmt->bindParam(2,$logged_user,PDO::PARAM_STR);
$i = 0;
foreach ($comments as $num)
{
$stmt->bindParam(1,$num,PDO::PARAM_INT);
if ($stmt->execute())
{
$i++;
}
}
$dbh = NULL;
echo " Comment(s) Removed " . $i);
exit();
Posted 04 October 2012 - 10:46 PM
adn258, on 05 October 2012 - 04:16 AM, said:
adn258, on 05 October 2012 - 04:16 AM, said:
Posted 04 October 2012 - 11:18 PM
adn258, on 05 October 2012 - 07:28 AM, said:
$query = "DELETE FROM comments WHERE ID=? AND poster=?;";
$stmt = $dbh->prepare($query);
$stmt->bindParam(2,$logged_user,PDO::PARAM_STR);
$i = 0;
foreach ($comments as $num)
{
$stmt->bindParam(1,$num,PDO::PARAM_INT);
if ($stmt->execute())
{
$i++;
}
}
$dbh = NULL;
echo " Comment(s) Removed " . $i);
exit();
$query = "DELETE FROM comments WHERE ID=? AND poster=?;";
$stmt = $dbh->prepare($query);
$stmt->bindParam(1, $num, PDO::PARAM_INT);
$stmt->bindValue(2, $logged_user, PDO::PARAM_STR);
foreach ($comments as $num)
{
if ($stmt->execute())
{
$i++;
}
}
echo " Comment(s) Removed " . $i);
This post has been edited by Dormilich: 04 October 2012 - 11:21 PM
Posted 05 October 2012 - 01:11 AM
This post has been edited by Dormilich: 05 October 2012 - 01:15 AM
Reason for edit:: removed unnecessary quote
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
