0

i have two database called "migrate_new" and "migrate_old" and both have one table called "cms_pages".

i want to compare "migrate_old" db "cms_pages" with the "migrate_new" "cms_pages" table structure if "migrate_new" database "cms_pages" does not have "field" then alter table automatically.

below is my code to compare "migrate_old" "cms_pages" fields not in "migrate_new" "cms_pages" now i want to add this fields on table. i want to continue the process in place of exit.

**> any one can have idea to add fields automatically so no need to stop migration task?

i am not able to get field details like type , key , etc. how i know alter table with use modify or add fields. i short i want to set structure with out loss of any data automatically. thanks in advance..
**

    $this->load->database();
    $admin_db = $this->load->database('ADMINDB', TRUE);

    $query = $this->db->get('cms_page');
    $result = $query->result();

    $fields_old = $this->db->list_fields('cms_page');
//  $fields_new = $admin_db->list_fields('cms_page');
    $flag = false;
    foreach ($fields_old as $field){

        if (!$admin_db->field_exists($field, 'cms_page'))
        {
            echo $field.'=> is not exists in new table please contact to developer for that <br>';
            $flag = true;
        }
    }

    if($flag){
        exit;           
    }
Utsav Naik
  • 15
  • 8
  • 2
    This is not a question, it's an annoucment. – lukelazarovic Sep 21 '15 at 10:38
  • What have you tried? What is the particular problem that you can't solve? If you want to know how to execute a DDL query in PHP, I'm sure there is plenty of Q&A addressing that. – lukelazarovic Sep 21 '15 at 10:48
  • possible duplicate of [How to add new column to MYSQL table](http://stackoverflow.com/questions/16113570/how-to-add-new-column-to-mysql-table) – lukelazarovic Sep 21 '15 at 10:50
  • i am not able to get field details like type , key , etc – Utsav Naik Sep 21 '15 at 11:07
  • http://stackoverflow.com/questions/5824722/mysqli-how-to-get-the-type-of-a-column-in-a-table – lukelazarovic Sep 21 '15 at 11:14
  • is there any code-igniter method to match fields all property? – Utsav Naik Sep 21 '15 at 11:24
  • [https://ellislab.com/codeigniter/user-guide/database/fields.html] **bold** how to put a where conditin on below example $fields = $this->db->field_data('table_name'); foreach ($fields as $field) { echo $field->name; echo $field->type; echo $field->max_length; echo $field->primary_key; } – Utsav Naik Sep 21 '15 at 11:26
  • i only want single fields details in side below condition to match the fields details. do i can identify alter with "ADD" or "Modify" keywords if (!$admin_db->field_exists($field, 'cms_page')) { } – Utsav Naik Sep 21 '15 at 11:35

0 Answers0