Understanding database migration in codeigniter - Abd Hannan
14935
post-template-default,single,single-post,postid-14935,single-format-standard,ajax_fade,page_not_loaded,,columns-4,qode-child-theme-ver-1.0.0,qode-theme-ver-10.0,wpb-js-composer js-comp-ver-4.12,vc_responsive

Understanding database migration in codeigniter

Understanding database migration in codeigniter

Hi, now I wanna explain how to understand database migration in CodeIgniter.

I assumed you already downloaded CodeIgniter and created a database called ‘ci_migrate’ for this practice.

Ok, now let’s open your CodeIgniter folder with your editor, and set up the config.php file on > codeigniter/config/config.php and set the base_url. also, setup database.php and choose your database name, user, and password as usual.

Now, create a new folder in codeigniter/applications/  called ‘migrations’ then create a new file on it give the name ‘001_user.php‘.

Write this code:

Open migration.php file in codeigniter/application/config/migration.php and set up like this one.

READ  Apa itu array_rand di php

 

Make new controller file on /codeigniter/application/controller/db_migrate.php

and create this code:

and run the code by type the URL on your browser:

READ  Memahami database migration di codeigniter

localhost/codeigniter/index.php/Db_migrate/

get back to your phpmyadmin and check your database, Voilaa the ‘user’ table alrady created with ‘migration’ table.

How to make other migration?

simply, create a new file on /codeigniter/migrations/002_employee.php

than create this code:

 

READ  Menghitung array dengan count()

if you call your Db_migrate conroller on your browser, it’s not affected.

You should modify first your Db_migrate.php controller file, like this:

what changed, btw?

The meaning is we choose version 2 (002_employee) to run when called on the browser.

Run your browser and check your database. Bingo 🙂

Comments

comments

1Comment
  • hannan
    Posted at 03:22h, 09 November

    This great