codeigniter 2 - How to do checking before importing the csv file by php? -


how checking before importing csv file in php?

i have csv file contains information columns id, name, telephone, email , have database same columns. have php file can import csv file database.

now, want update information batch, how can match id, name between csv file , database avoid wrong data input (suppose data in database correct in csv wrong).

at end, php can show message csv data incorrect! thanks! can help?

you can follows:

  • read csv using fread() , filesize()
  • explode() data, using linebreak (\n)
  • loop through each line of data foreach
  • explode each line, using comma (,)
  • test each index of array preg_match() , regex pattern make sure meets requirements
  • query database (in php, untested)

    $query = "update yourtable set name='".$name."' id='".$id."'";


make sure query santized using pdo or similar, avoid sql injection @ times.

that last bullet point key question, think. you'll need read update , insert sql queries - here's question may help: mysql function: insert if not exist or updated

you haven't included code or starting point in original question, can't specifics, i'm sure can research yourself. i'd it's easy-intermediate difficulty.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -