0

Controller:

$data['error'] = '';    //initialize image upload error array to empty

        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'csv';
        $config['max_size'] = '10000';

        $this->load->library('upload', $config);
        // If upload failed, display error
        if (!$this->upload->do_upload()) {
            $data['error'] = $this->upload->display_errors();
            $data['mainpage']='category';
            $data['mode']='addcsv';
            $this->load->view('includes/mainpage',$data);
//Category Id   Category Name   Sub-category Id Sub-category Name

        } else {
            $file_data = $this->upload->data();
            $file_path =  './uploads/'.$file_data['file_name'];

//            $cformat[0]="Category Id";
//          $cformat[1]="OrderName";
//          $cformat[2]="Relevancy";
//          $cformat[3]="Feedback";
            if ($this->csvimport->get_array($file_path)) {
                $csv_array = $this->csvimport->get_array($file_path);
                foreach ($csv_array as $row) {

                    $excel=array();
                    $cat_id=$row('Category Id');
                    $name=$row('Category Name');
                        $que= "INSERT INTO category (Caegory Id,Category Name)
                        VALUES ('$cat_id','$name')";
                    $excel=$que; 
                    $this->bulkupload_model->insert_csv($excel);



                }
                $this->flash->success('<h4>Csv Data Imported Successfully.</h4>');
                redirect(base_url().'uploads/index');

            } 
        else 
                $data['error'] = "Error occured";
                $data['mainpage']='category';
                $data['mode']='addcsv';
                $this->load->view('includes/mainpage',$data);

            }            

        }  

MODEL:

     $this->db->insert('category', $data);

IN Model how can i use auto commit can any one help me thanks in advance...

Edited by Dani: Formatting fixed

2
Contributors
1
Reply
18
Views
3 Years
Discussion Span
Last Post by veedeoo
0

Honestly, active record method

insert()

will only return boolean true or false after the query has been executed. If you want to make sure that the response is taking into consideration then, I strongly suggest for you to use transaction.

Pretty much you probably need to do the transaction manually.

Edited by veedeoo: info added.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.