我试图从csv文件中提取值提取到一个MySQL表。它运行但不填充表格。我试图调试过去的XXXX,但只是看不到我的错误。回应值给我正确的SQL,但是当涉及到INSERT时 - 没有骰子。从csv文件插入值到MySQL表
非常感谢您的帮助。
<?php
$host = 'localhost';
$user = 'fulltime_admin';
$pass = 'secret';
$database = 'fulltime_db';
$db = mysql_connect($host, $user, $pass);
mysql_query($database, $db);
//////////////////////////////// EDIT ////////////////////////////////////
$redirect_num = 500; // Select how many rows to insert each time before refresh.
// More rows = faster insertion. However cannot be too high otherwise it will timeout.
$filename = "ps4_emails.csv"; // The file we are going to get the data from...
$table = "`ps4_emails`";
////////////////////////////// END EDIT //////////////////////////////////
$file = file($filename);
$lines = count($file);
// Have we just redirected?
$nextline = $_GET['nextline'];
if (!isset($nextline)){
$nextline = 0;
}
$query = "INSERT INTO ".$table." (email) VALUES ('".$final_line[0]."')";
for ($line=$nextline; $line<=$lines; $line++){
$final_line = explode(",", $file[$line]);
if ($line!=$lines){
mysql_query($query,$db);
}
if ($line % $redirect_num){
// something needs to go here
} else {
$nextline = $line+1;
exit ('<meta http-equiv="refresh" content="0;url=texttomysqlemails.php?nextline='.$nextline.'" />');
}
echo ($line==$lines) ? "Done" : "";
}
?>
请勿使用mysql _ \ *函数。改为使用mysqli _ \ *或PDO与准备好的语句。 –
并更改您的数据库密码。 – ThiefMaster
那么你期望这个脚本运行多长时间?你有多少行加载到你的数据库 – RiggsFolly