minor #2855 Encourage using prepared statements (ntzm)

This PR was submitted for the 2.x branch but it was merged into the 1.x branch instead (closes #2855).

Discussion
----------

Encourage using prepared statements

Although the previous code isn't vulnerable, it could be if copied and used to store user input.

Commits
-------

97d9dc04 Encourage using prepared statements
This commit is contained in:
Fabien Potencier
2019-03-02 08:49:41 +01:00
+2 -2
View File
@@ -409,8 +409,8 @@ First, let's create a temporary in-memory SQLite3 database to work with::
{% block content %}Hello {{ name }}{% endblock %}
';
$now = time();
$dbh->exec("INSERT INTO templates (name, source, last_modified) VALUES ('base.twig', '$base', $now)");
$dbh->exec("INSERT INTO templates (name, source, last_modified) VALUES ('index.twig', '$index', $now)");
$dbh->prepare('INSERT INTO templates (name, source, last_modified) VALUES (?, ?, ?)')->execute(['base.twig', $base, $now]);
$dbh->prepare('INSERT INTO templates (name, source, last_modified) VALUES (?, ?, ?)')->execute(['index.twig', $index, $now]);
We have created a simple ``templates`` table that hosts two templates:
``base.twig`` and ``index.twig``.