在PHP中加载数据infile无法正常工作

时间:2017-08-07 02:19:45

标签: php mysql mysqli

我尝试使用加载数据infile在php中创建上传菜单导致我需要上传的文件太大

这是代码

<html>
<head>
</head>
<body>
    <?php
    include ("Connections/connection.php");
    if (isset($_POST["importodp"])) {
        if (!empty($_FILES["excelFile"]["tmp_name"])) {
            $filename = explode(".", $_FILES["excelFile"]["name"]);
            if ($filename[1] == "csv") {

                $file = addslashes($_FILES['excelFile']['tmp_name']);
                echo $file;

                mysqli_select_db($config, $database_config);
                $input_odp = "LOAD DATA LOCAL INFILE '$file' INTO TABLE `odp_report` FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n'";
                $run_input_odp = mysqli_query($config, $input_odp) or die(mysqli_error());

                if (!$run_input_odp) {
                    echo '<script type="text/javascript">alert("Data cannot uploaded")</script>';
                }
                if ($run_input_odp) {
                    echo '<script type="text/javascript">alert("Data successfully uploaded")</script>';
                }
            } else {
                echo 'Chose only csv file';
            }
        } else {
            echo 'Plese Select the file first...!!!';
        }
    }
    ?>
    <form action="" method="post" enctype="multipart/form-data">
        <input type="file" name="excelFile"/>
        <input type="submit" name="importodp" value="Import Data from Excel"/>
    </form>

</body>
</html>

但我得到的回报是:

  

警告:mysqli_error()需要1个参数,第21行给出0

我做错了吗?

1 个答案:

答案 0 :(得分:0)

语法:mysqli_error(connection);

参数:connection

说明:Required. Specifies the MySQL connection to use