‫All right.
‫So now we're going to start working with a database.
‫So any serious application will need some kind of database to store their data.
‫So a database is a collection of data.
‫It is a place where you can store data and then retrieve it later.
‫It's a way to organize data so that it's easy to find and easy to update.
‫And a database is very important part of any application.
‫Without a database, you would have to store all this data in files, and that would be very, very
‫difficult to manage.
‫So the type of data obviously depends on your application.
‫If you have a blog, you're most likely going to be storing things like blog posts, categories, comments,
‫users.
‫If you're building an e-commerce website, you're most likely going to have products and things like
‫that, orders, etcetera.
‫So everything that your application works with has to be stored in a database somewhere.
‫So in our project we're going to be creating a small job listing website.
‫So we'll be storing jobs and users because we'll also have authentication.
‫All right.
‫Now as far as which database to use you have a few options.
‫When when you're working with PHP I'd say the most popular are MySQL or MySQL, Postgres and SQLite.
‫And we'll be using MySQL for this course.
‫But the concepts that we'll be learning are applicable to all of them at least should say all the relational
‫SQL databases.
‫So MySQL is what we call a relational database.
‫This means that it stores data in tables.
‫And the tables can be related to each other.
‫And we'll be learning about how to create tables, insert data, how to retrieve data from them, display
‫them in our application.
‫There's also something called non-relational databases or NoSQL databases like MongoDB.
‫And these are becoming popular, but they're not used as much as relational databases, especially in
‫PHP.
‫PHP and MySQL have always had a really good relationship and has always been a really popular combination.
‫They work really well together, all right, and they use SQL.
‫So a relational database uses something called SQL which stands for Structured Query Language.
‫And it's it's basically a programming language.
‫I guess you could call it a programming language or a query language.
‫It makes more sense.
‫But it's used to to retrieve data, update, insert, delete order.
‫So all types of different operations you can do on a database and on the tables.
‫So we'll be learning a little bit of SQL in this course as well.
‫Now.
‫PHP has a built in extension called PDO, which stands for PHP Data Objects, and PDO is essentially
‫a database abstraction layer that allows us to connect to many different types of of SQL databases.
‫It also provides a common interface for working with databases.
‫This means that the code that you write will be the same no matter which database you're using, and
‫this is useful if you ever need to switch databases.
‫So let's say you want to go from MySQL to Postgres.
‫Well you can change up the connection and the credentials and all that.
‫And you won't have to rewrite your code.
‫PDO will use the same syntax, the same methods, and so on, no matter which SQL database you're using.
‫All right.
‫And PDO is also object oriented, which means that it uses objects to represent database connections
‫and queries.
‫And this is a very nice way to work with databases.
‫It's much easier than the old MySQL or MySQL extension, which is now deprecated.
‫You may at some point run into the MySQL or MySQL IE extension, but you'll probably only see that in
‫legacy code.
‫You don't really want to use that anymore.
‫So PDO also makes your application much more secure because many times the data being saved to a database
‫comes from user input, and you never want to blindly take what someone enters in a form and just store
‫it, because they can actually mess with the query.
‫And they can do things like drop your entire or delete your entire database.
‫So PDO uses something called prepared statements that ensure that data that's going to be entered is
‫treated as a string and not part of the query itself.
‫So it uses placeholders as opposed to just adding the user input directly to the query which is very
‫very dangerous.
‫All right.
‫So we'll get into all that in a little bit.
‫Now as far as database tooling or database management, there's a lot of tools that we can use to directly
‫access our data outside of our application.
‫So MySQL has a command line tool that we can use to connect to our database and run queries and basically
‫do everything we can do from within our application and more.
‫But I know that not everybody is comfortable with the command line.
‫So there are also graphical interfaces that we can use.
‫So some examples are MySQL workbench.
‫That's actually what we're going to be using in this course.
‫And when I say MySQL and MySQL interchangeably I mean the same thing.
‫So just just to let you know.
‫So MySQL workbench is a is a desktop application that's cross-platform.
‫So it doesn't matter if you're using Mac, windows, Linux.
‫That's why I chose it for this course because it's cross-platform.
‫It's easy to install.
‫PHP is another tool, but this is browser based.
‫So you would basically run it on your web server.
‫There's SQL Pro, there's Navicat table plus is really good, but it's premium.
‫So you do have to pay for it.
‫So I didn't want to use that in this course.
‫I don't want to use anything that you guys have to pay for it.
‫Heidi SQL is pretty popular.
‫It's been around for a long time.
‫Data grip.
‫There's there's so many of these and you might find something that you like better than MySQL workbench,
‫but I think that it's a good place to start.
‫Now.
‫Getting your system set up with, with MySQL is going to depend on how you have everything set up and
‫what operating system you're on.
‫So for myself, I'm on a mac and I just installed PHP with homebrew.
‫I'm using the local PHP server so I don't have well, I do have MySQL installed, but it didn't.
‫It didn't come with with PHP as it does when you're using something like Larrigan or Zamp or Mamp.
‫Those are software suites that come with PHP, MySQL and usually some other tools as well.
‫So if you're on a mac and you basically did what I did in this course, you're going to have to install
‫it separately, and I'm going to show you how to do that in the next video.
‫If you're on windows, what I'll do is make another video after that showing you how to how to use MySQL
‫through Larrigan.
‫And it's very similar if you're using Xampp or Mamp or any of those tools, it's pretty self-explanatory.
‫There's usually a button that says database or something like that.
‫And then I'm also going to jump into the command line so that we can run some queries, and I can show
‫you how to create a database and, you know, insert records and select records, stuff like that,
‫because we're going to be using the same SQL language that you use in your, in your application through
‫PDO.
‫All right.
‫So in the next video we'll look at getting set up on a mac.