Databases

Every example here starts by including database.php, which creates the $pdo connection. Read that file first — it is short.

Start here

1.1-starthere.html — What you need before you begin 2.database.php — The connection file
Nothing visible happens when you open it. Open it in your editor instead.

Reading (SELECT)

3.simpleRead.php — Query a table and show it 4.simpleRead2.php — A second reading example

Writing (INSERT)

5.simpleInsertExample.php — Insert, explained
Shows its own source rather than running.
6.insertPlay.php — A hardcoded insert 7.simpleInsert2.php — Insert with named placeholders 8.submitExample.php — Inserting many rows in a loop

Forms plus a database

9.form.php — A form and its GET data 10.simpleSubmit.php — Form to database
Posts across to simpleSubmitPost.php.
11.advanced.php — Several forms on one page

Doing it properly

12.properQuery.php — Why you must use placeholders
The commented-out "BAD!!!" version at the top is the one that gets you hacked. Read this one carefully.
13.functions.php — Putting queries into reusable functions 14.error.php — A shared "no permission" error page 15.settings.php — Loading site settings from a table
A pattern for values you want available everywhere.
16.apidemo/ — Separating queries into an API file
Keeps SQL out of your page code entirely.

Extras

12-explodeImplode.php — explode() and implode()
Turning one database field into a list and back again.
10-ajaxExample.html — A first taste of Ajax with a database 11-ajaxExample2.html — Ajax lookup by last name sql-recap/ — SELECT, INSERT and DELETE side by side
A compact review of the three operations.

The full Ajax section lives in 3 · Advanced.