Chapter Nine · The Real World

Databases in Real Applications

The Marquee's website is live, and nobody who uses it ever types a line of SQL — yet SQL runs on every click, and it is exactly the SQL you spent eight chapters learning. This chapter places your knowledge inside the real architecture: how applications hold connections and speak queries, the one attack every professional must understand, the accounts and permissions that bound the damage, the honest menu of places a database can live, and the libraries that write SQL so you don't have to. By the last page, "the app talks to the database" is not a phrase you nod along to — it is machinery you can draw.

5 topics

For eight chapters you have been the one talking to the database: typing queries, reading rows, booking G7 and G8 in one transaction. Real life is one step removed. Lora's customers book seats from their phones, on a website, and not one of them knows what a SELECT is. Between their tap and the bookings table sits a program — the Marquee's application — and that program speaks fluent SQL on their behalf, over a connection it keeps open all day. The language in the middle of that machinery is the one you already speak.

Five topics complete the picture. First, who actually talks to the database: browsers, app servers, connections, and where your queries physically travel. Then the page this chapter exists for: SQL injection, the twenty-five-year-old attack that happens when an app glues visitor text into its queries, and the parameter mechanism that ends it. Then accounts and permissions, which decide in advance how bad any future mistake can get. Then the geography question: your machine, a rented machine, a managed service, or no server at all. And finally ORMs — the libraries that write SQL from code, and why your SQL literacy is what makes them safe to use.

One click on the Marquee website — where your SQL actually lives
The three-layer picture this chapter draws
The browsera customer's phone or laptop
The app server — holds the connectionbuilds and sends the SQL you learned
The connection — your SQL travels hereSELECT … FROM bookings WHERE customer_id = 214
The databasethe four Marquee tables, guarded as ever

Topics in This Chapter