0

I am trying to insert a .txt file (converted to csv) into the database using the following:

while (($data = fgetcsv($prop, 1000, ",")) !== FALSE) {

When i try to do it with phpmyadmin with the file themselves it works, however the text does contain "," so i think it might be trying to read them as delimiters and throwing the results out. Can anyone help please?

the error is - 1. placing thousands of empty results 2. not placing the results in correct fields

thanks

meohmy
  • 131
  • 7
  • 17
  • Have you tried loading the file into (say) Excel and see how mangled it is? If there's embedded commas in the text, that particular field SHOULD be enclosed with quotes. if it's not, then your file is broken and needs to be tweaked before you can load it. – Marc B May 06 '12 at 22:18
  • thanks for this, opening the files in excel and all just opens into one field. whats the solution for this? – meohmy May 06 '12 at 22:24
  • How do you know the error is -1? Where do you read that error? What is the full error message? – hakre May 06 '12 at 22:40
  • no there are two errors, just marking the 1 and 2 – meohmy May 06 '12 at 22:43
  • tried str_getcsv and all sorts still cannot get this to work! any ideas please – meohmy May 06 '12 at 23:50
  • hey guys still not got a resolution to this, any ideas please would be amazing! – meohmy May 07 '12 at 21:43

1 Answers1

0

Consider using LOAD DATA INFILE (Link)

MonkeyMonkey
  • 826
  • 1
  • 6
  • 19