How to import data from csv to mysql with php codeigniter?

To import data from csv to mysql we need to convert excel file data to csv file and then upload using front end page using php codeigniter framework.
Now we will move to coding part ,Here we need to create three files in codeigniter folders i.e
1) Model file
2) View file
3) Controller file.
Now In the first step we will create View file as Upload_csv.php under View folder.


Now in the second step we will create controller file as User.php under controllers folder.
Here we are uploading the csv file using upload_sampledata function.

Now in the third step we will create Model file as upload_services.php under Models folder.


READ  Dropdown populate using Codeigniter and javascript

In the above code i used fgetcsv($fp,1024) to get csv line count and stored in $csv_line variable. Now using for loop read the csv file data and storing in an array and passing to codeigniter default insert function as shown above.
To maintain good website for online money making ,just take good Virtual Private Servers, Built for Open Source Developers , Fully managed, lightning-fast, starting at $15/mo with 1GB RAM! , a developer running a complex application that requires instant scalability, or a designer wanting to give your clients’ sites maximum performance, then VPS hosting is just what you need!
Thank you for reading this article.

6 Comments

  1. Alfredo Mattioli August 17, 2015
  2. Ady August 24, 2015
  3. Medbash August 27, 2015
    • joseph reddy August 28, 2015
  4. Akbar Shaikh June 6, 2016
    • admin June 21, 2016

Leave a Reply