-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use PDO prepared statement - avoid straw man #6665
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,9 +254,11 @@ an individual blog result based on a given id:: | |
function get_post_by_id($id) | ||
{ | ||
$link = open_database_connection(); | ||
$id = intval($id); | ||
$result = $link->query('SELECT created_at, title, body FROM post WHERE id = '.$id); | ||
$row = $result->fetch(PDO::FETCH_ASSOC); | ||
$query = 'SELECT created_at, title, body FROM post WHERE id=:id'; | ||
$statement = $pdo->prepare($query); | ||
$statement->bindParam(':id', $id, PDO::PARAM_INT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes you’re right, regards, .. matt ..
Dr. Matt Smith | Senior Lecturer in Computing | matt.smith@itb.ie Recent publications:
|
||
$statement->execute(); | ||
$row = $statement->fetch(PDO::FETCH_ASSOC); | ||
|
||
close_database_connection($link); | ||
|
||
|
@@ -294,9 +296,7 @@ Creating the second page is now very easy and no code is duplicated. Still, | |
this page introduces even more lingering problems that a framework can solve | ||
for you. For example, a missing or invalid ``id`` query parameter will cause | ||
the page to crash. It would be better if this caused a 404 page to be rendered, | ||
but this can't really be done easily yet. Worse, had you forgotten to clean | ||
the ``id`` parameter via the ``intval()`` function, your | ||
entire database would be at risk for an SQL injection attack. | ||
but this can't really be done easily yet. | ||
|
||
Another major problem is that each individual controller file must include | ||
the ``model.php`` file. What if each controller file suddenly needed to include | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$pdo
must be$link
here (or you need to rename the variable above).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry my mistake - I always use $pdo
yes, $link fits with existing code
regards,
.. matt ..
On Jun 21, 2016, at 07:57 AM, Christian Flothmann notifications@github.com wrote:
In book/from_flat_php_to_symfony2.rst: