Teda přátelé, to stím escapováním dat před ukládáním myslíte vážně? Není bezpečnějčí, elegantnější a "blbuvzdornější" použití navazování proměnných (omlouvám se překlad). Lepení vstupu do sql je kořenem všeho zla, použijte navazování proměnných. Viz. ospověď z jedné renomované databázové poradny:
oh, defending against SQL injection is trivial!!! really, it is.
Just never accept inputs from the end user that you glue into a sql
statement.
That's it -- never have something passed to you from the outside (outside YOUR
CODE) that becomes part of the query! SQL injection = thing of the past.
It is not dynamic sql that is the issue (all sql is dynamic in Oracle actually
-- even static sql in pro*c/plsql!). It is "the construction" of this sql that
is the problem.
If a user gives you inputs - they should be BOUND into the query -- not
concatenated. The second you concatenate user input into your SQL -- it is as
if you gave them the ability to pass you code and you execute that code. Plain
and simple.
Don't concatenate, but rather bind their inputs, and wah-lah, you are done.
The way to prevent it is via coding standards and design review. And -- best of
all -- at the end of the day, we achieve that nirvana that is "the applications
use binds!"
Myslí se tím nemíchání SQL dotazů s daty. Některé extenze (např. MySQL) to přímo nepodporují, jiné ano (např. MySQLi), existují také knihovny, které to zařídí (např. PEAR::DB). Kód pak může vypadat nějak takhle:
$stmt = $mysqli->prepare("SELECT * FROM tabulka WHERE nazev = ? OR id = ?");
$stmt->bind_param("si", $_GET["nazev"], $_GET["id"]);
$stmt->execute();