[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using LOAD DATA LOCAL INFILE

Posted on 2011-04-27
2
Medium Priority
?
673 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?
0
Comment
Question by:EddieShipman
  • 2
2 Comments
 
LVL 26

Accepted Solution

by:
EddieShipman earned 0 total points
ID: 35478544
Nevermind.
Here is the solution:

LOAD DATA LOCAL INFILE "c:/wamp/www/parts/Parts_Export9.csv"
INTO TABLE partnumbers 
IGNORE 1 LINES 
(@var1)
SET partnum=@var1;

Open in new window

0
 
LVL 26

Author Closing Comment

by:EddieShipman
ID: 35478548
Found solution on my own
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question