Hello,

Is it possible to do local data infile from a php file?

Here is the code I am using now:

$query = "LOAD DATA INFILE 'C:\file.txt' INTO TABLE file FIELDS TERMINATED BY '\t'";
$result = mysql_query($query);

When I run this php script, it didn't work but if I copy and paste the query to phpmyadmin, it works perfectly. So I am wondering if this is possible to be accomplished through a php script instead of phpmyadmin?

Any help would really be appreciated. Thanks!

-Renny

    <?php
    $db = mysql_connect("$id","$user");
    mysql_select_db ("fsftar") or die ("Sorry, database Problems. Please try again.");
    $drop = "DELETE FROM invoice";
    $dropresult = mysql_query($drop) or ("Cannot delete table");
    $query = "LOAD DATA INFILE 'arsummary.txt' INTO TABLE invoice FIELDS TERMINATED BY '~'";
    $result = mysql_query($query) or ("Cannot Load File");
    mysql_close($db);
    ?>

    this is the exact code I use to have mine work.

    The only thing I can think of is the LOAD LOCAL DATA INFILE because your using a windows file format. I am not sure, but it looks just like mine. I just put this up yesterday.

    hope this helps

      Write a Reply...