Jump to content


Photo

mysql LOAD command


  • Please log in to reply
6 replies to this topic

#1 liltbobas

liltbobas
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 February 2006 - 10:54 PM

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.

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 01 March 2006 - 01:26 AM

What's with all the spaces in the column names?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 liltbobas

liltbobas
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 01 March 2006 - 03:55 AM

i can't have spaces?

#4 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 01 March 2006 - 05:22 AM

Correctomundo.

#5 liltbobas

liltbobas
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 02 March 2006 - 08:25 PM

fixed spaces, still doesn't work. any other suggestions?

#6 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 03 March 2006 - 12:50 AM

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)?

#7 liltbobas

liltbobas
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 03 March 2006 - 05:59 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users