Import data from text file to mysql in php -


i want import data txt file mysql in php

my txt file as:

id    name    rollno      grno       inoutdatetime 1     test       1           1      10/4/2015 05:20:00 2     test2      2           2      11/4/2015 08:20:00 

and not have insert duplication of date data row

create database table columns according needs.

create table yourtablename (     id int,     name varchar(100),     rollno int,     grno int,     inoutdatetime varchar(100)     ) engine=innodb; 

if txt file follows same format example.

$fhandle=fopen("textfile.txt", "r"); fgets($fhandle); //first fgets read on header line.  while($line=fgets($fhandle)){     //explode line space delimeter     $words=explode(" ",$line);     /*         additional checks , data sanitizing here.     */     //if every line follows format in example, , not empty, insert table here     $sql="inser yourtablename            values ($words[0], $words[1], $words[2], $words[3], $words[4])"; } 

this gist overview of it. i'm sure there more things consider sanitizing data, null/duplicates checks, sql injection security, restructuring table column types etc..

hope helps!! :)


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -