0

I have been trying to use the following query

$query_name = "LOAD DATA INFILE '"
            . $file_path . 
            "' INTO TABLE '"
            . $this->table_name . 
             "' FIELDS TERMINATED BY ',' 
             LINES TERMINATED BY '\\n' 
             IGNORE 1 LINES 
             (time_stamp,curr_property,curr_property_cost,day_property,day_property_cost,curr_solar_generating,curr_solar_export,day_solar_generated,day_solar_export,curr_chan1,curr_chan2,curr_chan3,day_chan1,day_chan2,day_chan3)";
                $this->db->query($query_name);  

to upload my data into a database but the problem is that I am getting the following error

    Error Number: 1064

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 ''admin_tmp' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' ' at line 1

LOAD DATA LOCAL INFILE 'uploads/admin.csv' INTO TABLE 'admin_tmp' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES (time_stamp,curr_property,curr_property_cost,day_property,day_property_cost,curr_solar_generating,curr_solar_export,day_solar_generated,day_solar_export,curr_chan1,curr_chan2,curr_chan3,day_chan1,day_chan2,day_chan3)

I know that error 1064 is related to syntax but I don't see anything wrong with my code. Will be happy if someone could point out my mistake.

Bazinga777
  • 5,140
  • 13
  • 53
  • 92
  • 1
    See [When to use single quotes, double quotes, and backticks](http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks). The table name `admin_tmp` should be unquoted or backtick-quoted, _not_ single quoted. – Michael Berkowski May 07 '14 at 20:54
  • Note that if you execute this from the web, you are probably going to need an absolute path to the CSV file. `/path/to/uploads/admin.csv` – Michael Berkowski May 07 '14 at 20:57
  • Thanks Mike, for the help and also for the link to the resource. – Bazinga777 May 07 '14 at 21:02

0 Answers0