Case Study: from Installation till Access Database with Code Igniter

: Webserver Package (AppServ, XAMPP, EasyPHP, etc) & Code Igniter

CodeIgniter (CI) is a PHP framework, say, for people who want to build a website using PHP. With the model-view-controller architecture that separates between the logic and the display of the program, CI is quite “fun” enough to used. It is not difficult. Just prepare 2 cups of hot coffee to begin learning it :)

Step 1: Installation

1. Extracts CodeIgniter bundle (that you’ve downloaded) in your web server’s root directory.
2. You will see so many folders …. okay, do not worry. Go to the system-application folder.
3. Well .. part in this application folder is what you will “care” often later :)

Step 2: Configuration

1. Open the config.php file located in the application-system-config-config.php
2. Change the base url, adjust to the location where your folders CI are (extracts folder). Example: Your CI folder is in the www/ci folder.
Then change the line $config ['base_url'] = "";
$config ['base_url'] = "http://localhost/ci/";
Why localhost? Since in this tutorial we will build the CI in our local server:)
3. Setting the database. Open database.php files that are in the same folder as config.php. Change the hostname, username, password (according to your mysql setting) and name of the database (we will create the database later, now just preparing for the name first). Example :
$db ['default'] ['hostname'] = "localhost";
$db ['default'] ['username'] = "root";
$db ['default'] ['password'] = "";
$db ['default'] ['database'] = "db_ci";

We’re done with the installation and configuration, next step we will prepare a database that we use in this laboratorium (laboratorium ha ha, please dont imagine like we’re done something biology okay :) )

Step 3: Prepare the database

1. Create a database with the name db_ci through your phpmyadmin (I assume you already familiar with this great tool.)
2. Prepare a table with name tb_buku (field: id_buku, judul_buku, stok_buku).
`Id_buku` varchar (10) NOT NULL,
`Judul_buku` varchar (50) DEFAULT NULL,
`Stok_buku` year (4) DEFAULT NULL,
PRIMARY KEY (`id_buku`)
) ENGINE = MyISAM DEFAULT charset = latin1;

3. Insert a few sample data into tb_buku.
INSERT INTO `tb_buku` (`id_buku`, `judul_buku`, `stok_buku`) VALUES
('1 ',' Search Button Tab ', 2003),
('2 ',' To order from the King ', 2033);

4. Ok, we’re done with the database!

Step 4: Working with CI

1. Make a model. Type the following script

class Buku_model extends Model {
function Buku_model()
function getBuku() {
$data = $this->db->get('');
return $data;

2. Save with the name buku_model.php. Store in system-application-models folder
3. Make Controller. Type the following script,

class Buku_con extends Controller {
public function Buku_con()
public function getBuku () {
$data['title'] = ‘menampilkan isi buku’;
$data['detail'] = $this->buku_model->getBuku();
$this->load->view(‘buku_view’, $data);

4. Save with the name buku_con.php. Store in system-application-controller folder.
5. Create View. Type the script,
<h4> Data Book </h4>
<?php foreach ($detail-> result () as $rows):
echo $rows-> id_buku; echo "<br>";
echo $rows-> judul_buku; echo "<br>";
echo $rows-> stok_buku; echo "<br>";

6. Save with the name buku_view.php. Save in system-application-views folder
7. Hohoh. We’ve created a function to display data from the database with the controller, model, and view… Now go to your browser.
8. Type http://localhost/ci/buku_con/getBuku/. And … TADAAAA

Data Buku dari Database
9. You are allowed to sleep after seeing the picture like above :)

Step 5: Prepare the third coffee and opened the Yahoo Messenger.

Happy Coding Chatting! :D
Hal yang juga menarik:

Hak Cipta

Semua skrip dan teknik dalam artikel di boleh digunakan sebagaimana kehendakmu tanpa perlu mencantumkan sumber. Kamu tidak boleh mengkopi seluruh artikel, dalam Bahasa Indonesia ataupun diterjemahkan ke dalam bahasa lain.

Related Articles:

Artikel terkait:


About the author

obviously, a girl. with sweet smile, off course. turning her 21 years trapped on Informatics departement and just started to having some crush with it lately. she uses wordpress. she loves php. she lo

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

x( X-( B-) ;-) :wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :arrow: :D :?: :-| :-x :-o :-P :-D :-? :-)) :-) :-( :-& :) :( :!: 8-O 8-) 8) (Русский) (yahoo) (worship) (woot) (wave) (unsure) (tongue) (thinking) (tears) (taser) (smileydance) (sleeping) (sick) (scenic) (rofl) (rock) (party) (panic) (okok) (nottalking) (ninja) (music) (muscle) (muhaha) (money) (mmm) (lonely) (lol) (lmao) (idiot) (hungry) (highfive) (heart_beat) (heart) (headspin) (hassle) (haha) (gym) (griltongue) (goodluck) (girlkiss) (funkydance) (fish_hit) (eyeroll) (evilsmirk) (evil_grin) (drinking) (doh) (devil) (dance) (cry) (cozy) (coffee) (brokenheart) (bringit) (blush) (bigeyes) (beer) (banana_rock) (banana_ninja) (banana_cool) (applause) (annoyed) (angry) (K) (: