Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

text file import error

Status
Not open for further replies.

nalmond

Technical User
Mar 20, 2002
21
CA
MYSQL / PHP Newbie question

I'm using MySQL 4.0.14-nt and php4 on a win2000 box running pws. I've noticed from previous posts that importing from textfiles issues are a regular thread. I've tried the fixes used in a number of previous threads to no avail.

When I execute the follwing command from a .php webpage:
$query = "LOAD DATA INFILE 'D:\Profiles\nalmond\Desktop\dates.txt' REPLACE INTO TABLE dates FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\n'";

$result = mysql_query($query) or die ("Invalid DATA LOAD query");

I get an error and the 'or die' error message is diplayed. Other php/MySQL commands such as 'Optimise Table' run OK. The text file is tab delimited, although I have tried it as a CSV also without success.

When I try to import the file via an admin front end, SQLFront, I get the following error:

'ERROR 1148: THE USED COMMAND IS NOT ALLOWED WITH THIS MySQL VERSION'

I've checked that 'Allow use of LOAD DATA LOCAL INFILE' is enabled via MySQL CC.

I've run out of ideas, can anyone help?
 
LOAD DATA LOCAL is problematic.

First of all, you're not asking your script for the right information. Why are you using " or die ("Invalid DATA LOAD query");" when you could be using " or die (mysql_error());"? This will give you more information about what is going wrong.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Thanks for the response sleipnir214,

I now get the error:
Parse error: parse error in c:\inetpub\Team_Nortime\php_samples\import_data.php on line 15

Line 15 is the containing the ?> php closing tag

Here's the full code:

<?php
# MySQL database User ID, Password and DB name
$sql_id = &quot;******&quot;;
$sql_pwd = &quot;******&quot;;
$sql_db = &quot;******&quot;;
$sql_host = &quot;localhost&quot;;

# Connect to the database
$connection = mysql_connect($sql_host,$sql_id,$sql_pwd) or die (&quot;Couldn't connect to server&quot;);
$db = mysql_select_db($sql_db,$connection) or die (&quot;Couldn't connect to database&quot;);
$query = &quot;LOAD DATA INFILE 'D:\Profiles\nalmond\Desktop\dates.txt' REPLACE INTO TABLE dates FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\n'&quot;;
$result = mysql_query($query) or die (mysql_error());&quot;?
?>
 
A &quot;parse error&quot; line number is the line at which PHP realizes it's confused, not the line at which the confusion began. With parse errors, the error is nearly certainly somewhere before the line number reported in the error.

One thing I noticed is the filename you're using in your query. Did you know the string &quot;\n&quot; appears in that filename, and that PHP is going to interpret that string as a newline? Replace your backslashes in the filename with either forward slashes or double-backslashes. Print out the query as a debugging step to make sure it's right.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top