Import CSV file to MySQL database

I have entries in a .CSV file and I want to import them into a MySQL .

Whenever I import .CSV , I get an Import has been successfully finished... message, but only 79 out of 114 entries are inserted into the database.

When I try to import a .CSV file with 411 entries, I only need to insert 282. The CSV file that received 411 entries includes two categories of Active and Sold entries, in which 114 entries are active.

Has anyone got this problem? If so, what should I do?

+6
source share
3 answers

I wrote my own csv importer with php. I use the php fgetcsv command to read the csv file, and then I use the mysql insert command in a loop.

  $ handle = fopen ($ this-> file, "r");
 $ i = 0;
 $ delimiter = ($ this-> fieldDelimiter == 'TAB')?  chr (9): $ this-> fieldDelimiter;
 while (($ data = fgetcsv ($ handle, 10000, $ delimiter))! == FALSE)
 {
      $ mydata [] = $ data;
 }
 fclose ($ handle);
 reset ($ mydata);
 if ($ this-> CSVhasTitle)
 {
       $ mydata = array_slice ($ mydata, 1);  // delete first row
 }

Then I go through my array and I use mysql insert:

  foreach ($ mydata as $ value) 
 {
      INSERT INTO $ table (...) VALUES (....)
 } 

But I add the exact column names to the array before the loop. I have an array of all columns.

+1
source

I also had this problem. Despite being slightly outdated and these recommendations go in the same direction, this is the solution I found. I created a large database and imported and had the same thing, after testing and testing, I realized that the key was created somehow assigned (I did not recognize it because I used a new skin and always used the old skin). He pulled out a key, which somehow did not get me, but left the main one and the boom, absorbed the data loading. Also, you are having trouble submitting, and request a time regarding your question. I pushed the viewer display a lot to thousands and now I'm stuck, I can’t access the configuration file somewhere with my CP. Since it will hang and support customer support, to be lazy, to read my problems and redefine them at the end, I will have to delete the whole table, and not any DROP, since it can not even run SQL as a hang with overload. So food for thought was to keep you down in the dining room view, which sucks, as in my case. B / c I need to look at 17,000 rcords visually quickly to ensure that my .csv was correct and not functioning as if problems could then be detected and correct in control, which makes more sense to me anyway .

+1
source

Take a look at your CSV file. Most likely it’s something like

  1,2, "some data", 1
 2.5, "data, with, comma", 2

If you do not specify COLUMNS, SINGLE_QUOTE DOUBLE_QUOTE SINGLE_QUOTE MUST BE COMPLETED, then the commas embedded in the row data in the second row, the third column will not be imported properly.

Check the CSV to find out which shell symbol is used, and specify this in the phpmyadmin interface.

0
source

Source: https://habr.com/ru/post/921889/


All Articles