In this CodeIgniter tutorial , i will show you how to fetch data from database using model ,view, controller approach.
As usually we need need to setup database connection in order to perform actions like select,insert,delete,update..etc on database. open your database.php file and setup the database configuration values, after setting up database connection , As we know, CodeIgniter use MVC pattern. We will use Model for retrieve data from 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.
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.
No comments:
Post a Comment