我目前正在编写一个简单的PHP脚本,以便它可以读取日志文件并将数据放入MySQL数据库。在此期间,它还向网站发出Web请求,以向我提供一些数据,这些数据也将被插入到MySQL数据库中。我预计它会插入500条记录,然后将我重定向到我的主页,但是,它总是以服务器错误结束,当我检查数据库时,它只能输入大约65-70条记录。我已经检查过,并且日志文件没有问题,因为脚本的记录数量较少,例如请帮忙。(PHP + MySQL)总是给第65条记录服务器错误
<?php
//Make a connection
$connection = mysql_connect("localhost:3306", "root", "XXXXXXXX");
//Select a table
$db_select = mysql_select_db("major_project", $connection);
//open file
$report = fopen('C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\HN.F\report.txt', 'r') or exit("Unable to open report.txt");
//insert operation
while(!feof($report))
{
$array = explode("\t", fgets($report));
list($seg, $ts, $rule, $sev, $ref, $ref2, $source, $sourcep, $dest, $destp, $ser) = $array;
if($seg != 'Segment')
{
if(count($array) == 12)
{
list($seg, $ts, $rule, $sev, $ref, $ref2, $source, $sourcep, $dest, $destp, $ser) = $array;
$ipaddrloc = fopen('http://freegeoip.appspot.com/json/'.$source, 'r');
while(!feof($ipaddrloc))
{
$var = fgets($ipaddrloc);
$lat = json_decode($var)->latitude;
$long = json_decode($var)->longitude;
$country = json_decode($var)->countryname;
$city = json_decode($var)->city;
}
mysql_query("INSERT INTO `major_project`.`logs` (`LOG_NUMBER`, `Segment`, `Timestamp`, `Rule`, `Severity`, `Reference system`, `Reference`, `Source`, `Source port`, `Dest.`, `Dest. port`, `Service`, `Country`, `City`, `Latitude`, `Longitude`) VALUES (null, '$seg', '$ts', '$rule', '$sev', '$ref', '$ref2', '$source', '$sourcep', '$dest', '$destp', '$ser', '$country', '$city', '$lat', '$long')");
}
else
{
list($seg, $ts, $rule, $sev, $ref, $ref2, $source, $sourcep, $flag, $dest, $destp, $ser) = $array;
$ipaddrloc = fopen('http://freegeoip.appspot.com/json/'.$source, 'r');
while(!feof($ipaddrloc))
{
$var = fgets($ipaddrloc);
$lat = json_decode($var)->latitude;
$long = json_decode($var)->longitude;
$country = json_decode($var)->countryname;
$city = json_decode($var)->city;
}
mysql_query("INSERT INTO `major_project`.`logs` (`LOG_NUMBER`, `Segment`, `Timestamp`, `Rule`, `Severity`, `Reference system`, `Reference`, `Source`, `Source port`, `Flag`, `Dest.`, `Dest. port`, `Service`, `Country`, `City`, `Latitude`, `Longitude`) VALUES (null, '$seg', '$ts', '$rule', '$sev', '$ref', '$ref2', '$source', '$sourcep', '$flag', '$dest', '$destp', '$ser', '$country', '$city', '$lat', '$long')");
}
}
}
header("Location: startpage.html");
?>
将错误粘贴错误比您的代码更有用 – 2010-12-07 11:48:42
如果您获得一个500,有一个`error.log`可以告诉你更多的地方。你有访问权限吗? – 2010-12-07 11:51:39