Welcome Guest, Not a member yet? Register   Sign In
Creating Tables
#1

Hello,

I use to work with Laravel and I want to know if there is any way such as migrantion in laravel for Codeigniter I mean to create tables and roles of them then just run it in command and it creates tables automatically so no need to work on my phpmyadmin and input many lines of codes to create tables, is there?

Thanks.
Reply
#2

(05-08-2017, 04:43 PM)robertnicjoo Wrote: Hello,

I use to work with Laravel and I want to know if there is any way such as migrantion in laravel for Codeigniter I mean to create tables and roles of them then just run it in command and it creates tables automatically so no need to work on my phpmyadmin and input many lines of codes to create tables, is there?

Thanks.


Hi, there is an ugly way to do something like this:

PHP Code:
$source $this->load->database('source_db'TRUE);
$target $this->load->database('target_db'TRUE);

$this->myforge $this->load->dbforge($targettrue);

 
$fields $source->field_data($table);
 
           
                    $fields2 
= array();
 
                   foreach ($fields as $fld)
 
                   {
 
                       $fields2[$fld->name        = (array) $fld;
 
                       $fields2[$fld->name]['null'] = true;

 
                       unset($fields2[$fld->name]['name']);

 
                       if ($fields2[$fld->name]['default'])
 
                       {
 
                           $fields2[$fld->name]['default'] = (string) $fields2[$fld->name]['default'];
 
                       } else
 
                       {
 
                           unset($fields2[$fld->name]['default']);
 
                       }

 
                       if ($fields2[$fld->name]['max_length'])
 
                       {
 
                           $fields2[$fld->name]['constraint'] = (int) $fields2[$fld->name]['max_length'];
 
                           unset($fields2[$fld->name]['max_length']);
 
                       }

 
                       unset($fields2[$fld->name]['primary_key']);
 
                   }

 
                   $this->myforge->add_field($fields2);
 
                   $this->myforge->create_table($tableTRUE);                 
Reply
#3

I think you have to read the docs first. CodeIgniter has a very nice documentation.

https://www.codeigniter.com/user_guide/l...ation.html

its also available in your local copy under user_guide
God Bless CI Contributors Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB