How to Import and Export CSV Files Using Codeigniter and MySQL
In this Post We Will Explain About is How to Import and Export CSV Files Using Codeigniter and MySQL With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Import CSV Data into Mysql in Codeigniter Example
In this post we will show you Best way to implement php – How do I import CSV to mysql using codeigniter, hear for How To Import CSV Data Into Mysql Using Codeigniter with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
controllers – Ci_csvImp.php
load->model('csv_import_ci_model'); $this->load->library('csvimport'); } function index() { $this->load->view('csv_import'); } function load_data() { $result = $this->csv_import_ci_model->select(); $output = 'Imported Student Information from CSV File
'; echo $output; } function import() { $file_data = $this->csvimport->get_array($_FILES["csv_file"]["tmp_name"]); foreach($file_data as $row) { $data[] = array( 'studfname' => $row["First Name"], 'studlname' => $row["Last Name"], 'stud_mobile' => $row["Phone"], 'email' => $row["Email"] ); } $this->csv_import_ci_model->insert($data); } }
'; $count = 0; if($result->num_rows() > 0) { foreach($result->result() as $row) { $count = $count + 1; $output .= ' Sr. No Student First Name Student Last Name Student Mobile Student Email '; } } else { $output .= ' '.$count.' '.$row->studfname.' '.$row->studlname.' '.$row->stud_mobile.' '.$row->email.' '; } $output .= ' any student Data not Available
models – Ci_csvImp_model.php
db->order_by('id', 'DESC'); $query = $this->db->get('student_list'); return $query; } function insert($data) { $this->db->insert_batch('student_list', $data); } }
views – csv_import.php
How to Import CSV Data into Mysql using Codeigniter
Database: `liveatm`
-- -- Database: `liveatm` -- ------------------ -- Table structure for table `student_list` -- CREATE TABLE IF NOT EXISTS `student_list` ( `id` int(11) NOT NULL, `studfname` varchar(250) NOT NULL, `studlname` varchar(250) NOT NULL, `stud_mobile` varchar(30) NOT NULL, `email` varchar(200) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Indexes for dumped tables -- -- -- Indexes for table `student_list` -- ALTER TABLE `student_list` ADD PRIMARY KEY (`id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `student_list` -- ALTER TABLE `student_list` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example
I hope you have Got What is How to import CSV files in MySql using CodeIgnitor And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.