Jump to content

Archived

This topic is now archived and is closed to further replies.

liltbobas

mysql LOAD command

Recommended Posts

I'm trying to build a script to load tab delimited text files into my database, but I can't get a working query. Here's what I got:

$command = mysql_query ("LOAD DATA LOCAL INFILE '/file.txt' INTO TABLE electronics FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' (ITEM NUMBER, ITEM NAME, CATEGORY, SUB-CATEGORY, DESCRIPTION, WEIGHT, WHOLESALE PRICE, RETAIL PRICE, SHIPPING, HANDLING, CARRIER NAME, QUANTITY IN STOCK, IMAGE SMALL, IMAGE MEDIUM, IMAGE LARGE, DETAIL URL)");

if ($command) {

echo "<br>good";

} else {

echo "<br>bad";

}

It returns bad every time. Any suggestions? Thanks.

Share this post


Link to post
Share on other sites
What's with all the spaces in the column names?

Share this post


Link to post
Share on other sites
Try echoing mysql_error() after the query.

Does mysqld have permission to read the file in question? Is the file on the database server (instead of the web server, if they're different)? Does the file use unix-style line feeds (\n)?

Share this post


Link to post
Share on other sites
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''electronics'' at line 1

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.