csv格式的数据输入到mysql,带有分隔符

w7t8yxp5  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(328)

我想导入一个csv格式的输入列表,带有分隔符(|),从一个textarea到我的mysql数据库。
但它总是失败,如果它的格式正确的话。
它传达了这样一个信息: Error, 0 added successfully. 我的格式:

Thomas|Maier|5778011152|Bahnweg|232

有人有主意吗?

if(isset($_POST["base_name"]) && isset($_POST["new_entry"])) {
    $myList = preg_replace("/\r|\n/", "", preg_split("/$\R?^/m", $_POST["new_entry"]));
    foreach($myList as $info) $csv[] = explode($_POST["separator"], $info);

    $csvParams = $csv[0];
    array_shift($csv);

    $success = 0;
    $total = 0;

    foreach($csv as $info) {
        $sqlInsert = array_combine($csvParams, $info);
        $sqlInsert["base"] = $_POST["base_name"];
        $sqlInsert["info"] = "unbenutzt";

        $p = softwareInsertArray($softwareSqlLink, $sqlInsert, "person");
        if($p) $success++;
        $total++;
    }

    $q = softwareRunQuery($softwareSqlLink, false, "INSERT INTO statistics (`key`, `val`) VALUES ('".$_POST["base_name"]."|profit', '0');");
}

if(isset($total)) {
    if($total == $success && $total > 0 && $q) {
        $alert = array("type" => "success", "header" => "Erfolgreich!", "text" => "Success.");
        softwareSqlLog($softwareSqlLink, "person", array("status" => 1, "info" => array("base" => $_POST["base_name"], "text" => $success." person added successfully")));
    } else {
        $alert = array("type" => "danger", "header" => "Fehler!", "text" => $success."/".$total." sucess.");
        softwareSqlLog($softwareSqlLink, "person", array("status" => 0, "info" => array("base" => $_POST["base_name"], "text" => $success."/".$total." added.")));
    }
}

softwareinsertarray代码:pastebin.com/raw/vunqtpxu

mqxuamgl

mqxuamgl1#

你只想用逗号替换管道吗?ie选择替换('thomas | maier | 5778011152 | bahnweg | 232','|',',')

相关问题