tags:

views:

62

answers:

3

I have a MySQL file which I want to import via PHP 5.

In the name of user friendliness the user should not use tools like PHPmyadmin etc. Just hit a button and the file will get imported.

I have already created code to upload the file to a location on the server.

The file looks like this:

INSERT INTO products VALUES ('', '0', '10', '', '1', 'be34112', '4536.jpg', '','','','0');
SET @master_id = LAST_INSERT_ID();
INSERT INTO products_description VALUES ('', '1', @master_id, '1', 'Kjole', '', 'beskrivelse', '2000', '25', 'kjole.xml', '', '', '');
INSERT INTO products_to_categories VALUES ('',@master_id,'5');
INSERT INTO products VALUES ('', @master_id, '10', '12', '1', 'be34112', '4536.jpg', '200','','','0');
SET @variant_id = LAST_INSERT_ID();
INSERT INTO products_description VALUES ('', '1', @variant_id, '1', 'Kjole', '', 'beskrivelse', '2000', '25', 'kjole.xml', '', '', '');
INSERT INTO options_to_products VALUES ('', @variant_id, '1', '1');
INSERT INTO options_to_products VALUES ('', @variant_id, '', '2');
INSERT INTO products VALUES ('', @master_id, '20', '17', '1', 'be34113', '4537.jpg', '200','','','0');
SET @variant_id = LAST_INSERT_ID();
INSERT INTO products_description VALUES ('', '1', @variant_id, '1', 'Kjole', '', 'beskrivelse æøå ÆØÅ & íjj´¨¨¨¨fdfd""', '3000', '25', 'kjole.xml', '', '', '');
INSERT INTO options_to_products VALUES ('', @variant_id, '1', '');
INSERT INTO options_to_products VALUES ('', @variant_id, '', '4');
+3  A: 

Load the file into a string and then pass it to mysqli::multi_query().

Standard disclaimers regarding untrusted sources for data/queries/executable-code et cetera apply.

Amber
+1  A: 

you can pass it to mysqli_multi_query

knittl
A: 

With very big files, I would tend to try and split the files myself. I asked a similar question a while back and got pretty good results.

Pekka