我正在努力将我的PDO插入到textarea的数据库中,其中包含以下信息:
USER1 | PASS1 用户2 | PASS2 用户3 | PASS3
目前的问题是此列表的最后一个帐户多次插入我的数据库,但我无法理解为什么会发生这种情况。这是我的代码:
// Divide the textarea by line into a string array
$accounts = explode(PHP_EOL, $_POST['accountData']);
// Prepare the Query
$query = "INSERT INTO accounts (username, password, referral, dateCreated,region,idOrder) VALUES ";
// Create the multiple value placeholder
$qPart = array_fill(0, sizeof($accounts), "(?, ?, ?, ?, ?, ?)");
$query .= implode(",",$qPart);
$stmt = $dbh->prepare($query);
$idOrder=100;
switch($priority)
{
case("low"):
$date="2050-01-01 00:00:00.000";
$i = 1;
foreach($accounts as $item){
list($user, $pass) = explode("|", $item);
echo $user . ":" . $pass . "<br>";
$stmt->bindParam($i++, $user);
$stmt->bindParam($i++, $pass);
$stmt->bindParam($i++, $refid);
$stmt->bindParam($i++, $date);
$stmt->bindParam($i++, $region);
$stmt->bindParam($i++, $idOrder);
}
break;
case("high"):
$date="2000-01-01 00:00:00.000";
foreach($accounts as $item){
list($user, $pass) = explode("|", $item);
echo $user . ":" . $pass . "<br>";
$stmt->bindParam($i++, $user);
$stmt->bindParam($i++, $pass);
$stmt->bindParam($i++, $refid);
$stmt->bindParam($i++, $date);
$stmt->bindParam($i++, $region);
$stmt->bindParam($i++, $idOrder);
}
break;
}
$stmt->execute();
我echod $ user和$ pass,它显示了正确的用户:pass(= 3个不同的用户和密码)。但是在DB中只有LAST用户多次插入。你能救我吗?
答案 0 :(得分:1)