LOAD DATA LOCAL INFILE help...

freecrm

New Member
Messages
629
Reaction score
0
Points
0
I've done quite a bit of reading on this but the subject is fraught with pitfalls.

I need to import data from a local csv file and have created the following code (adds to existing data).

<?php
require_once('Connections/freecrm.php');

mysql_select_db($database_freecrm, $freecrm)
or die("Could not open database");

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$varfilepath=$_POST['filepath'];
$sql =
"
LOAD DATA LOCAL INFILE '$varfilepath'
INTO TABLE TEST
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
";
$result = mysql_query($sql)
or die ("Could not import data.");
}
?>

In the body, I have a form with 1 field (the file path), 1 hidden field to fulfil the "if" criteria and a submit button.

But I'm getting the response "Could not import data." which means I'm getting the connection but for some reason, it aint working!

Have I got a simple Syntax problem here or am I missing the point?

The page is currently at www.freecrm.x10hosting.com/test.php
Edit:
Does anyone have any idea what I'm on about?
 
Last edited:

marshian

New Member
Messages
526
Reaction score
9
Points
0
Try to use mysql_error() to know more about the error mysql encounters.
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
Try to use mysql_error() to know more about the error mysql encounters.

Good advice :) and it did help a lot!

I have added this into the code and narrowed the error to these lines..

OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\n'

which I have now removed!

Now I'm getting this error..

File 'C:\Temp\testdata.csv' not found (Errcode: 2)

I've tried to reverse the \ to / but no change. Bizarre!
 
Top