我在mySql db中有表,我想上传csv文件。我在localhost XAMPP窗口上使用它。当我将其输入PHPmyAdmin时,它可以工作:
LOAD DATA LOCAL INFILE 'D:/10-xampp/htdocs/csvuploader/handling-fees.csv'
INTO TABLE `dvtbl_getquotehc`
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES
表格已更新 但是当我在php文件中使用这个代码时,没有错误,但表仍然是空的
try {
Db::queryAll("LOAD DATA LOCAL INFILE '?'
INTO TABLE `dvtbl_getquotehc`
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES
",array('D:/10-xampp/htdocs/csvuploader/handling-fees.csv'));
} catch (PDOException $ex)
{
echo 'PDO ERROR: '.$ex->getMessage();
}
PHP代码有什么问题? DB类只是PDO包装器库。
编辑1
使用mysqli帮助和更新作品。但我仍然不知道PDO风格有什么问题。下面的Mysqli版本
$sql = "LOAD DATA LOCAL INFILE '".$changedrealpath."' REPLACE INTO TABLE dvtbl_getquotehc
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\\r\\n'
IGNORE 1 LINES";
//Try to execute query (not stmt) and catch mysqli error from engine and php error
if (!($stmt = $mysqli->query($sql))) {
echo "\nQuery execute failed: ERRNO: (" . $mysqli->errno . ") " . $mysqli->error;
};
编辑2
问题可能出在准备好的陈述中。当我使用pdo-> exec时,它可以工作。这段代码适合我:
$pdo->exec("LOAD DATA LOCAL INFILE '$fileName' REPLACE
INTO TABLE `$hcTable`
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\\r\\n'
IGNORE 1 LINES
");
} catch (PDOException $ex)
{
echo 'PDO ERROR: '.$ex->getMessage();
}