Skip to content
Try the admin demo 0
In plain words

PDO, or why a search box cannot empty your database

Every site keeps its content in a database, and every page asks that database questions. How it asks decides whether the site can be broken into.

The old way, and what is wrong with it

The careless way to ask is to glue the question and the answer into one sentence of text: find the user whose name is — and then whatever the visitor typed, pasted straight in.

Which is fine until somebody types something that is not a name but an instruction. The database has no way to tell the two apart: it was handed one sentence and it reads all of it as a command. That is SQL injection, and it is still one of the commonest ways sites are emptied, defaced or read.

What PDO does instead

PDO sends the question and the values along separate paths. The database is told the shape of the query first — find the user whose name is (a value goes here) — and only then given the value. By that point the query is already understood, and there is no way for a value to become part of it.

A visitor can type an entire instruction into the search box and it will be looked for, letter for letter, as a name. It cannot be executed, because it never arrives anywhere it could be.

What this means for your site

  • The commonest break-in on the web does not work here, by construction rather than by vigilance.
  • Every query in this CMS goes through PDO with its values kept separate.
  • It is also portable: the same code speaks to MySQL, MariaDB and others without rewriting.