nun*_*unu 2 php mysql load-data-infile
我有这个错误:
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";
Run Code Online (Sandbox Code Playgroud)
尝试这种语法后:
$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);
Run Code Online (Sandbox Code Playgroud)
将备份文件还原到新服务器后会发生此错误.从错误消息我可以看到已经创建的临时文件.
编辑
我试过了:
mysql --load-infile -u root -p pwd DBname
然后尝试将上面的查询放在里面>mysql,这个查询可以工作.但是,为什么如果我使用PHP它不?
尝试编辑/etc/mysql/my.cnf:
add local-infile = 1
仍然无法正常工作.这个php页面
问题解决了
只是改变:
$dbc=mysql_connect(_SRV, _ACCID, _PWD) or die(_ERROR15.": ".mysql_error());
Run Code Online (Sandbox Code Playgroud)
进入:
$dbc=mysql_connect(_SRV, _ACCID, _PWD,false,128) or die(_ERROR15.": ".mysql_error());
Run Code Online (Sandbox Code Playgroud)
Tadaaa ......所有的错误都消失了!!