' PDOException'在上传CSV时使用消息' SQLSTATE [HY000]

时间:2016-12-08 15:09:22

标签: php sql csv pdo upload

我尝试通过PHP PDO功能将CSV文件上传到MySQL数据库。 CSV由html表单上传并保存在服务器上。在此之后我做了一些验证(我已经从下面的代码中排除了这个)。但是我很确定它是有用的,我上传了几次成功的CSV文件,但一周之后就停止了以下错误代码:

Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General      error: 7890 Can't find file

这是我使用的代码:

$csv_upload_status = "none";
$sec_pass = "4220334";

$databasehost = "127.0.0.3"; 
$databasename = "database_name"; 
$databasetable = "table_name"; 
$databaseusername="database_user"; 
$databasepassword = "XXXXXXXXXXXX"; 
$fieldseparator = ","; 
$lineseparator = "\r";


if(isset($_POST["submit"])) {

$valid = 1;
$target_dir = "schedule-uploads/";
$target_file = $target_dir . basename($_FILES["csv"]["name"]);
$FileType = pathinfo($target_file,PATHINFO_EXTENSION);

if ($valid == 1) {  

    move_uploaded_file($_FILES["csv"]["tmp_name"], $target_file);

    $csvfile = basename( $_FILES["csv"]["name"]);


    try {
        $pdo = new PDO("mysql:host=$databasehost;dbname=$databasename", 
            $databaseusername, $databasepassword,
            array(
                PDO::MYSQL_ATTR_LOCAL_INFILE => true,
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
            )
        );
    } catch (PDOException $e) {
        die("database connection failed: ".$e->getMessage());
    }

    $affectedRows = $pdo->exec("
        LOAD DATA LOCAL INFILE ".$pdo->quote($csvfile)." INTO TABLE `$databasetable`
          FIELDS TERMINATED BY ".$pdo->quote($fieldseparator)."
          LINES TERMINATED BY ".$pdo->quote($lineseparator)."
          (@date, show_time, show_title, show_plot)
          SET show_date = STR_TO_DATE(@date, '%m/%d/%Y');");

    $csv_upload_status = "success";

}

}

0 个答案:

没有答案