0
votes

I want to save my CSV File data to my database and using "Load Data Infile" as-

$sql="LOAD DATA INFILE '".$tempLoc."'
      INTO TABLE `tbl_csv`
  FIELDS
  TERMINATED BY ','
  ENCLOSED BY '\"'
  LINES
  TERMINATED BY '\r\n'
 (`mobile`, `name`, `email`) ";

I keep getting syntax errors for this query statement.

Error: CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 13 Can't get stat of '/tmp/phpikiYm6' (Errcode: 2). //tmp/phpikiYm6 is the file name

2

2 Answers

0
votes

Sorry but I have no much reputations to comment on your question, however I cant see that you give the file extension to the query, have you tried:

$sql="LOAD DATA INFILE '".$tempLoc.".csv' INTO TABLE tbl_csv FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' (mobile, name, email) ";

0
votes

Follow given checks to fix this problem :

perror 13 OS error code 13: Permission denied

Check these variables (using SHOW VARIABLES):

have_csv = YES
local_infile = ON

If those are correct, then...

The .csv file, I think, needs to be readable and locatable by the "mysql" user. Note that both "r" and "x" is needed on directories to let a user 'read' and 'search' the directory.

Suggest you change permissions on the file and directories of this part to 777: