我有一个 CSV 文件上传到与包含我想从数据库中的表(一次全部)中删除的人的电子邮件地址的文件相同的目录中。我使用的代码正确回显,但不会从表中删除任何内容。CSV 文件与包含以下代码的文件上传到同一目录。
<?php
// Make a MySQL Connection
mysql_connect("x", "x", "x") or die(mysql_error());
mysql_select_db("volunteers2012") or die(mysql_error());
mysql_query($sql);
/********************************/
$addresses = file('deleteEmails.csv');
foreach($addresses as $address) {
$safe_address = mysql_real_escape_string($address);
$sql = "DELETE FROM vols2012 WHERE `email` = '$safe_address'";
$result = mysql_query($sql) or die(mysql_error());
}
echo "DELETION A GREAT SUCCESS!";
?>
第 2 轮 - 尝试使用 .txt 文件
<?php
// Make a MySQL Connection
mysql_connect("x", "x", "x") or die(mysql_error());
mysql_select_db("volunteers2012") or die(mysql_error());
mysql_query($sql);
/********************************/
$addresses = "LOAD DATA LOCAL INFILE ('deleteEmails.txt')";
foreach($addresses as $address) {
$safe_address = mysql_real_escape_string($address);
$sql = "DELETE FROM vols2012 WHERE (email = '$safe_address')";
$result = mysql_query($sql) or die(mysql_error());
}
echo "DELETION A GREAT SUCCESS!";
?>
我仍然收到成功回声,但是为foreach()
.