0

How do I load data into an EAV table from a CSV file in MYSQL database?

My CSV file is like this:

"ID",    "attr1",    "attr2",    "attr3",
"ID1",   "value1",   "value2",   "value3",

I tried using a script to change the CSV file into EAV CSV file but I think that won't be scalable.

user1471283
  • 381
  • 1
  • 4
  • 12

2 Answers2

0

Have you tried making use of fgetcsv function in PHP ?. Manual

Without showing what you have tried we could not able to help.

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
0

You should transform your usually CSV

Max;Mustermann;Hamburg;Am Elbufer 123
Jens;Mander;Manderscheid;Eisgasse 99

into another CSV with exact 3 fields like this:

addr01=name=Mustermann
addr01=vname=Max
addr01=ort=Hamburg
addr01=str=Am Elbufer 123
addr02=name=Mander
addr02=vname=Jens
addr02=ort=Manderscheid
addr02=str=Eisgasse 99

Now, always having 3 fields: Entity, Attribute, Value.

By the way, in Perl a Hash of Hashes, also means EAV:

$EAV = {
    addr01 = {
        name  => 'Mustermann',
        vname => 'Max',
        ort   => 'Hamburg',
        str   => 'Am Elbufer 123',
    },
    addr02 = {
        name  => 'Mander',
        vname => 'Jens',
        ort   => 'Manderscheid',
        str   => 'Eisgasse 99',
    },
};
LittleBobbyTables - Au Revoir
  • 32,008
  • 25
  • 109
  • 114
Rolf
  • 19
  • 3