📄️ Section Intro
Alright guys, so we have a working router that can handle multiple types of requests. We're still mapping routes to a single file. We'll change it to work with a controller class later on. Right now, I want to focus on the database. We're going to be using MySQL and PDO to connect to the database. We'll start our database class which will connect and we'll also have a query method. Just like with everything else, we'll start simple and add features as we go along.
📄️ Setting Up Our Database
We will need to setup a database for our job listings and users. I will be using MySQL along with MySQL Workbench. If you do not have a connection setup in MySQL Workbench, do that now. I should you how to do that a couple of sections back.
📄️ Database Class & Connection
In the database section, we looked at how to use PDO, which is a PHP extension that allows us to connect to and query a database. We also looked at how to use prepared statements to prevent SQL injection attacks. We will be using PDO in this project, but we will be creating a class to make it easier to use. This will include connecting to the database, preparing statements, binding values, returning results and more.
📄️ query Method
Now that we have a class for our database and a connection, let's add a method to query the database. We will call it query and it will take in a SQL query string and return the results.
📄️ Pass Data To The View
Now that we can get data from the database from within the controller, we need a way to pass it to the view. We will do this by adding a second parameter to the loadView function.
📄️ Show Single Listing
Now we are going to be working on the details/show page. This will show all the details of a single listing.
📄️ Display Listing View
We have the data from the database, now we need to display it in the view.