Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
There are many options for working with databases in PHP, such as MySQL, PostgreSQL and SQLite. If you work with PDO then you can connect to any of them with the same code, so learn how to do it once and be able to work with other systems much more easily in the future.
[NOISE] When you build an aggregation with
PHP 99% of
0:00
the time you'll be interacting with some
sort of data store.
0:04
And this is very often an SQL database.
0:09
SQL stands for structured query language.
0:12
If you're unfamiliar with SQL databases,
you should check out the course,
0:15
database foundations.
0:19
SQL databases allow you to save users,
blog posts,
0:22
payment information, and whatever else
your website will need to remember, and
0:25
provides you with an interface to fetch
that data back whenever you need it.
0:28
There are many options for
0:31
working with databases in PHP, such as
MySQL, PostgreSQL, and SQLite.
0:34
MySQL is incredibly popular with the PHP
community.
0:39
But if you end up using that, you have to
be careful.
0:41
There are three extensions that can be
used to connect to
0:45
MySQL databases and PHP.
0:48
MySQL, MySQLI, and PDO.
0:50
The MySQL extension is currently
deprecated, and
0:53
will be removed from the upcoming version
of PHP.
0:56
You shouldn't use this for anything
anymore.
0:59
MySQLI and PDO are the only remaining safe
options.
1:01
If you are not using MySQL and decide to
go with another popular system,
1:04
like Postgres or SQL Lite, then there are
extensions for
1:07
that too, such as PGSQL, SQLite, and also
PDO.
1:10
If you are unsure which to use, a sensible
option is to always work with PDO.
1:15
PDO allows you to learn one PHP API for
interacting with many supported databases.
1:20
This allows you to use the same API to
interact with MySQL, Postgres, and SQLite,
1:25
or many others without having to relearn a
brand new set of functions and classes.
1:30
You need to sign up for Treehouse in order to download course files.
Sign up