How to retrieve data from database in CodeIgniter?

In this CodeIgniter tutorial, I will show you how to fetch data from database using model, view, controller approach.

As usual, we need need to setup database connection in order to perform actions like select, insert, delete, update..etc in the database. open your database.php file and set up the database configuration values, after setting up the database connection, As we know, CodeIgniter use MVC pattern. We will use Model to retrieve data from the database.

open your application/database.php, set your database credentials.

Then create a controller called Post.php in you application/controller/ directory.

Now create you model file called PostModel.php in our Application/Models/ directory.Which will query the database table and fetch the records.

the final step lets create posts_view.php file under folder name application/views. Here we are going to display the posts information.

Now point your browser to http://localhost/post/ you will get the result.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets. Protection Status