Search code examples
phpmysqlcsvload-data-infile

Cannot get Load Data Infile To Work


Here is my LOAD DATA script. I cannot get it to work. Any one have any heads up on what I can do? Thanks!

$sql = "
LOAD DATA INFILE ".$theFile."
REPLACE INTO TABLE Product
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n'
(archived_id_number, sku, name, upc, account_id, shippingBox_id, unit_cost, supplier_id, description, productLength, productWidth, productHeight)";

Here is what and example of my txt file(s) looks like:

 43485|7850|Cool Circuits|630227078508|74||10.00|545||0.00|0.00|0.00
 39682|7802|Light|630227078027|74||10.00|545||0.00|0.00|0.00

Here is the error that I get:

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 '/home/hallow8/public_html/xxxx/scripts/productsNew2/data_science_wiz.txt' at line 1

Solution

  • You need quotes around the path

    $sql = "
    LOAD DATA INFILE '".$theFile."'
    REPLACE INTO TABLE Product…