Site icon WDB24

Slim 3 Framework Tutorial: Create, Configure, Load and Access Database

slim3 featured image

This is the second article of the slim 3 framework tutorial. In my previous article we have successfully downloaded slim 3 framework and worked with routes and templates.

If you directly land on this page just to understand how to access database in slim 3 then this tutorial is for you. But if you want to develop website using slim 3 then please also read my previous post for better understanding.

Also read: Slim 3 Framework Tutorial: Download, Setup, Create Routes and Template

In this slim 3 framework tutorial I am going to configure and access database. We already created home page and about page in our previous post. In this post I will create blog listing page and show records from database.


Create, Configure, Load and Access Database in Slim 3 Framework:

Following are the step by step process of how we will create blog page.

Create Database:

Create Database Table:

Set Database Variable in settings.php:

Database Connection in index.php:

This is a beginner tutorial so I am using mysqli class to access database but it is better to use PDO.

Create Route for Blog:

View Blog.php:

Blog.php file is located in templates folder.

Exit mobile version