Source File link is Here
- Open your Dreamweaver or Notepad editor and create new PHP Page and name it import.php
- Now include csv_importer.php file in your page like below.
- include ( "csv_importer.php" );
- For Connecting MySQL Database please write following line
- $conn = @mysql_connect("localhost","root","password");
- Now choose your database like below
- @mysql_select_db("yourdbname",$conn);
- 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";
- Now you have to set columns of table according to your CSV file Template
$c->SetColumnSequence("Field1,Field2,Field3,Field4,Field5");
- Here you will write csv file reference from which your data will be imported to Table
- $result = $c->import("Your_CSV_Name.csv",$conn);
- Now include csv_importer.php file in your page like below.
if($result === FALSE) { there was some error importing data $c->DumpErrors(); } else { Your data imported successfully, it will print number of rows inserted. print "Total records inserted are $result in table $c->table"; }
- in the end you will close MySQL Connection
- @mysql_close();
No comments:
Post a Comment