1

I have csv file exported from access. (dates formatted to match mysql)

I need to import the data into a mysql DB through code.

when I import the file through PhpMyAdmin it worked beautifully.

$fname = $_FILES['sel_file']['name'];
$filename = $_FILES['sel_file']['tmp_name'];
$sql="LOAD DATA INFILE '../filepath/data.txt' INTO TABLE table1 FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"';";
 mysql_query($sql)or die(mysql_error());

I tried using the file path or using the variable $filename and both gave me the same error

I get the following error:

Access denied for user 'uname'@'%' (using password: YES) I set the permissions to be 777, The databse was created allowing direct access. (I am able to opload the file and read from it using an "INSERT" statement, but not load data.)

A. Is the LOAD DATA statement wrong?

B. What other things do I have to take care of in order to use the LOAD DATA command.

Thank you all!

NinaNa
  • 1,575
  • 6
  • 15
  • 21

2 Answers2

3

Try LOAD DATA LOCAL INFILE

thavan
  • 2,409
  • 24
  • 32
  • Viola! That did something. thanks! now I have to make sure the data is going in as it should... I really appreciate it! what does LOCAL mean? – NinaNa Feb 06 '12 at 12:40
  • 2
    You are trying to upload something from client side. So you have to use the LOCAL keyword. As stated in mysql site - The LOCAL keyword, if specified, is interpreted with respect to the client end of the connection. – thavan Feb 06 '12 at 12:54
0

It may be a authentication problem. Please check the permissions for Import/export data in mysql.

Muthu Krishnan
  • 1,664
  • 2
  • 10
  • 15
  • As far as I can tell the permissions should be ok. I am able to import the data looping through the file and using an INSERT statement but that is way too slow. Can you be more specific on what permissions I should check? – NinaNa Feb 06 '12 at 12:37
  • @NinaNa: Please check this [link](http://stackoverflow.com/questions/1014724/mysql-permission-errors-with-load-data) – Muthu Krishnan Feb 06 '12 at 13:21