Search code examples
phpmysqlload-data-infile

Got error message in LOAD DATA LOCAL INFILE


I've got this error:

Error message is :: "Error occured during query execution: (LOAD DATA LOCAL INFILE '/tmp/3sch.jofcial.txtgymCN5' REPLACE INTO TABLE `prod_sch` FIELDS TERMINATED BY ',' IGNORE 1 LINES (No_ ,Model_Code,Model_Name ,Lot_No_ ,Start_Seq_No_ ,Quantity ,Lot_Quantity ,Line_Code ,Line_Name ,@var10, Shift_No1,@var12,Shift_No2,@var14,Production_Mngm_Type,Model_Group,Model_Category,Actual_Results,MPS_Mngm_Code, Production_Mngm_Code,Comment) SET Production_Start_Date=STR_TO_DATE(@var10,'%m/%d/%Y'), Production_Finish_Date=STR_TO_DATE(@var12,'%m/%d/%Y'), Due_date=STR_TO_DATE(@var14,'%m/%d/%Y')): The used command is not allowed with this MySQL version";

After try this syntax:

$temp_file = tempnam(sys_get_temp_dir(), '3sch.jofcial.txt');  // make temporary file name
$fp = fopen($temp_file, "wb");          // open temprary file
if (!$fp) die(_ERROR14);
fwrite($fp, $httpfile);                         // copy to temporary file from schedule file
fclose($fp);
chmod($temp_file, 0644);                        // file mode change for read only

$sql="TRUNCATE TABLE `prod_sch`";
$res=mysql_query($sql) ;//or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() );  // submit SQL to MySQL $
$sql="LOAD DATA LOCAL INFILE '".$temp_file."' REPLACE INTO TABLE `prod_sch` FIELDS TERMINATED BY ',' IGNORE 1 LINES "; // FIELDS ENCLOSED BY '\"'$
$sql.="(No_ ,Model_Code,Model_Name ,Lot_No_ ,Start_Seq_No_ ,Quantity ,Lot_Quantity ,Line_Code ,Line_Name ,@var10, ";
$sql.="Shift_No1,@var12,Shift_No2,@var14,Production_Mngm_Type,Model_Group,Model_Category,Actual_Results,MPS_Mngm_Code, ";
$sql.="Production_Mngm_Code,Comment) ";
$sql.="SET Production_Start_Date=STR_TO_DATE(@var10,'%m/%d/%Y'), ";
$sql.="Production_Finish_Date=STR_TO_DATE(@var12,'%m/%d/%Y'), ";
$sql.="Due_date=STR_TO_DATE(@var14,'%m/%d/%Y')";

$res=mysql_query($sql) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() );  // submit SQL to MySQL and$
unlink($temp_file);

This error happen after restore the backup file into new server. From the error message I can see that the temporary file already created.


EDIT

I have try:

mysql --load-infile -u root -p pwd DBname

then try to put the query above inside >mysql, this query can work. But, why if i using php it doesn't?

try to edit /etc/mysql/my.cnf: add local-infile = 1 still can't work. this the php page


Solution

  • Problem solved

    Just change:

    $dbc=mysql_connect(_SRV, _ACCID, _PWD) or die(_ERROR15.": ".mysql_error());
    

    Into :

    $dbc=mysql_connect(_SRV, _ACCID, _PWD,false,128) or die(_ERROR15.": ".mysql_error());
    

    Tadaaa...all error is gone!!