- Before we dive deeper,
let's look a little bit at the basics around databases.
First of all, what are databases?
They're usually a large collection
of data organized for rapid search and retrieval.
This definition is not bound to computers actually.
Anything index can be a database.
Think about phone books,
we know that even ancient cultures had a way to
record their bookkeeping in a way
so that it could be easily retrieved.
Fact is there was never so much data to store
and retrieve than it is today.
Think about big data.
If we talk about databases in programming
there are some basic concepts all databases have in common.
First of all, a database comes
with a database management system
DBMS often referred to as the database server.
This is an application of its own
and for web application development,
it has to run either on the host where the application runs
or on a dedicated host it can be reached
from your application.
Usually a DBMS provides a way to organize data.
This is often referred to as tables or collections.
A table or a collection contains related data.
So for a shop you might create the table items
which contains the items in the shop.
Additionally, most DBMS also support indexes.
These are dedicated data structures that contain parts
of the data for fast retrieval.
So in a shopping system, you might put an index
on the item number.
The data structure for the index
will them contain a list of item numbers
with the reference to the record in the table.
If you query for this item number
the DBMS will not scan through the whole table
but first use this index.
In the end the data has to live somewhere
on either disk or in some cases in memory.
And to make this less abstract
here's an example of how one of the mysql databases
that we will create in this course will look like on this.
You see that each table is represented by one file.
How this data is really stored,
this means the structure
of this database files largely depends on the DBMS
and it's really a science of its own.
With the database in place
we of course want to access this data from our applications.
For that we usually have to install a client
library that provides us with an interface
or API to easily communicate with the DBMS.
The library will then
under the hood connect to the database management system
either via TCP/IP or by a socket connection,
and it will take care of storing
and retrieving the data
using a communication protocol specific
to the given database.