CSV Importer in MySQL

Furqan Aziz | 06 Sep 2013 | Tutorials

CSV Importer in MySQL
Social Box
CSV importer is a PHP file which can help you to import all your data in MySQL Database using CSV File. Source File csv_importer.php is also available with this tutorial.
  1. Open your Dreamweaver or Notepad editor and create new PHP Page and name it import.php
  2. Now include csv_importer.php file in your page like below.
    • include ( "csv_importer.php" );
  3. For Connecting MySQL Database please write following line
    • $conn = @mysql_connect("localhost","root","password");
  4. Now choose your database like below
    • @mysql_select_db("yourdbname",$conn);
  5. Now write below lines . you just need to provide your table name where you want to import data. leave all other lines as it is.
    • create new importer object for importing data
      $c = new CSV_Importer;
      display log errors at end           
      $c->log_errors = true;
      skip the very first row in CSV file         
      $c->skip_top   = true;
      Type of Server (default MYSQL), you can also use this  MSSQL and PGSQL          
      $c->server     = MYSQL; 
      Database Table where File will be imported         
      $c->table      = "yourtablename";
  6. Now you have to set columns of table according to your CSV file Template
    • $c->SetColumnSequence("Field1,Field2,Field3,Field4,Field5");
  7. Here you will write csv file reference from which your data will be imported to Table
    • $result = $c->import("Your_CSV_Name.csv",$conn);
  8. Now include csv_importer.php file in your page like below.
    • if($result === FALSE)
      there was some error importing data
      Your data imported successfully, it will print number of rows inserted.
      print "Total records inserted are $result in table $c->table";
  9. in the end you will close MySQL Connection
    • @mysql_close();
Above tutorial is based on scriptbaba 2009 scripts. Now that website is not working so I write this tutorial for you. For more information please post a comment on Crewow Blog
PHP MySQL Simple Delete using PDO in Bootstrap Tutorial
Convert Simple Text To 3D Text using Adobe Fireworks CS6 Tutorial
PHP Simple Update using PDO in Bootstrap Tutorial
PHP Simple Insert using PDO in Bootstrap Tutorial
PHP MySQL Easy CSV Data Insertion in Bootstrap using PDO Tutorial
PHP Easy Sign-in Using PDO Prepared Statement Tutorial
Easy PHP Email With Attachments using Swift Mailer Tutorial
Easy Pagination with PDO in PHP plus Export to Excel Tutorial
PHP PDO to Connect MySQL Database Tutorial
Best CSS Frameworks Collection For Rapid Web Development
PHP-MySQL Ajax Jquery-UI Autocomplete in Bootstrap Tutorial
PHP Simple Sign-in Tutorials
Jquery Raty Usage via PHP
PHP Dynamic Select options Via Ajax
CSV Importer in MySQL
PHP File Load Via Jquery into DIV
© 2018 CreWow Network - All Rights Reserved.