Database
Definition
Organised storage for website data – user accounts, products, orders, content. Websites query databases to display and update information.
What is a Database?
A database is structured storage for information that websites need to function. When you create an account, place an order, or post a comment, that data is stored in a database. When you view a product page, the content is retrieved from a database.
Any website with dynamic content – content that changes or is personalised – uses a database.
How Databases Work
Databases organise data into tables (like spreadsheets) with rows and columns. A users table might have columns for email, password, name, and created date. Each user is a row.
Websites query databases using languages like SQL:
- "Show me all products under £50"
- "Find the user with this email address"
- "Add this order to the orders table"
Types of Databases
Relational (SQL)
Organised into tables with defined relationships. Most common for websites.
- MySQL – powers WordPress, most PHP sites
- PostgreSQL – powerful, popular with modern apps
- SQLite – lightweight, file-based
Non-Relational (NoSQL)
More flexible structure, good for specific use cases.
- MongoDB – document-based, flexible schema
- Redis – in-memory, used for caching
- Firebase – real-time, mobile-friendly
What Databases Store
| Data Type | Examples |
|---|---|
| User data | Accounts, profiles, preferences |
| Content | Blog posts, pages, products |
| Transactions | Orders, payments, bookings |
| Sessions | Login status, shopping carts |
| Analytics | Page views, events, behaviour |
Database and Website Performance
Database queries can be slow if not optimised. Common issues:
- Missing indexes (like a book without an index)
- Poorly written queries
- Too many queries per page load
- Insufficient server resources
Good database performance is crucial for fast page loads, especially on dynamic sites like WordPress or e-commerce platforms.