Merge pull request #540 from aykutfarsak/patch-1

Update 07-03-01-Databases_PDO.md
This commit is contained in:
Phil Sturgeon
2015-01-22 15:00:35 -05:00

View File

@@ -50,7 +50,7 @@ FROM users` which will delete all of your users! Instead, you should sanitize th
<?php <?php
$pdo = new PDO('sqlite:/path/db/users.db'); $pdo = new PDO('sqlite:/path/db/users.db');
$stmt = $pdo->prepare('SELECT name FROM users WHERE id = :id'); $stmt = $pdo->prepare('SELECT name FROM users WHERE id = :id');
$id = filter_input(FILTER_GET, 'id', FILTER_SANITIZE_NUMBER_INT); // <-- filter your data first (see [Data Filtering](#data_filtering)), especially important for INSERT, UPDATE, etc. $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); // <-- filter your data first (see [Data Filtering](#data_filtering)), especially important for INSERT, UPDATE, etc.
$stmt->bindParam(':id', $id, PDO::PARAM_INT); // <-- Automatically sanitized for SQL by PDO $stmt->bindParam(':id', $id, PDO::PARAM_INT); // <-- Automatically sanitized for SQL by PDO
$stmt->execute(); $stmt->execute();
{% endhighlight %} {% endhighlight %}