mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-11 00:03:58 +02:00
Merge pull request #540 from aykutfarsak/patch-1
Update 07-03-01-Databases_PDO.md
This commit is contained in:
@@ -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 %}
|
||||||
|
Reference in New Issue
Block a user