Import MySQL file in PHP
- by Cudos
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');