We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Using LOAD DATA LOCAL INFILE

Eddie Shipman
on
Medium Priority
691 Views
Last Modified: 2012-05-11
In PHP, can I use LOAD DATA LOCAL INFILE to import a CSV file with one column into a table with 3 columns?
I want the data from the CSV file to go into the middle column (partnum) in the table.
Schema for table:
CREATE TABLE `partnumbers` (
	`id` INT(10) NOT NULL AUTO_INCREMENT,
	`partnum` VARCHAR(50) NULL DEFAULT NULL,
	`webflis` TINYINT(10) NULL DEFAULT NULL,
	INDEX `Index 1` (`id`),
	INDEX `Index 2` (`partnum`, `webflis`)
)
COLLATE='latin1_swedish_ci'
ENGINE=MyISAM
ROW_FORMAT=DEFAULT

Open in new window


Sample data:
PART_NUMBER
1813R
632440
069-00200
92D24-3
83D55-1
88060-4A
714708
2882

Open in new window


Tried this but it doesn't enter the partnum value:
LOAD DATA LOCAL INFILE "c:/wamp/www/parts/Parts_Export9.csv"  INTO TABLE partnumbers IGNORE 1 LINES (@dummy, partnum, @dummy2)

Open in new window


Can this be done or do I have to use fgetcsv?
Comment
Watch Question

All-around developer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Eddie ShipmanAll-around developer
CERTIFIED EXPERT

Author

Commented:
Found solution on my own
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.