我有一个相当长的脚本,一直运行到昨晚(没有做出任何改动,我知道)。
需要运行的查询是:
$query = "INSERT INTO results SET
compId = ".$comp_id.",
eventId = ".$eventId.",
eventSession = '".$eventsession."',
driverId = ".$driverid.",
teamId = ".$teamid.",
position = ".$this->data['drivers']['position'][$i].",
raceTime = '".$racetime."',
laps = ".$this->data['drivers']['laps'][$i].",
pitstops = ".$this->data['drivers']['pitstops'][$i].",
engine = ".$engineId.",
tyres = '4',
sector1 = '".$sector1."',
sector2 = '".$sector2."',
sector3 = '".$sector3."',
fastestLap = '".$this->data['drivers']['bestTime'][$i]."',
grid = ".$grid;
// If debug is true then just var_dump but don't execute query
if ($this->debug) {
var_dump($query); echo '<br>';
}
else { // debug is false here, then not debug and run mysql query as usual
mysql_query($query);
}
我运行了一个debug / var_dump脚本,该脚本显示所有数据都已正确读取,并显示脚本正确运行数据集中的每条记录:
string(341) "INSERT INTO results SET compId = 8, eventId = 934, eventSession = 'P', driverId = 408, teamId = 142, position = 1, raceTime = '', laps = 9, pitstops = 0, engine = 57, tyres = '4', sector1 = '34.8867', sector2 = '35.8517', sector3 = '35.7191', fastestLap = '106.4575', grid = 0"
string(342) "INSERT INTO results SET compId = 8, eventId = 934, eventSession = 'P', driverId = 1910, teamId = 316, position = 2, raceTime = '', laps = 9, pitstops = 0, engine = 57, tyres = '4', sector1 = '35.0853', sector2 = '35.6669', sector3 = '35.7169', fastestLap = '106.4692', grid = 0"
string(343) "INSERT INTO results SET compId = 8, eventId = 934, eventSession = 'P', driverId = 1934, teamId = 201, position = 3, raceTime = '', laps = 11, pitstops = 0, engine = 51, tyres = '4', sector1 = '35.1301', sector2 = '35.7618', sector3 = '35.7473', fastestLap = '106.6393', grid = 0"
string(343) "INSERT INTO results SET compId = 8, eventId = 934, eventSession = 'P', driverId = 1263, teamId = 286, position = 4, raceTime = '', laps = 10, pitstops = 0, engine = 53, tyres = '4', sector1 = '35.0674', sector2 = '35.7036', sector3 = '35.9128', fastestLap = '106.6838', grid = 0"
string(342) "INSERT INTO results SET compId = 8, eventId = 934, eventSession = 'P', driverId = 1255, teamId = 286, position = 5, raceTime = '', laps = 8, pitstops = 3, engine = 53, tyres = '4', sector1 = '35.1663', sector2 = '35.9540', sector3 = '35.6342', fastestLap = '106.7544', grid = 0"
string(340) "INSERT INTO results SET compId = 8, eventId = 934, eventSession = 'P', driverId = 1190, teamId = 8, position = 6, raceTime = '', laps = 3, pitstops = 0, engine = 51, tyres = '4', sector1 = '35.1284', sector2 = '35.8531', sector3 = '35.8777', fastestLap = '106.8593', grid = 0"
string(342) "INSERT INTO results SET compId = 8, eventId = 934, eventSession = 'P', driverId = 1092, teamId = 253, position = 7, raceTime = '', laps = 8, pitstops = 1, engine = 55, tyres = '4', sector1 = '35.2606', sector2 = '35.9344', sector3 = '35.7010', fastestLap = '106.8960', grid = 0"
string(342) "INSERT INTO results SET compId = 8, eventId = 934, eventSession = 'P', driverId = 1393, teamId = 154, position = 8, raceTime = '', laps = 9, pitstops = 0, engine = 58, tyres = '4', sector1 = '35.1497', sector2 = '35.8700', sector3 = '36.0847', fastestLap = '107.1044', grid = 0"
string(342) "INSERT INTO results SET compId = 8, eventId = 934, eventSession = 'P', driverId = 2048, teamId = 251, position = 9, raceTime = '', laps = 9, pitstops = 1, engine = 55, tyres = '4', sector1 = '35.2091', sector2 = '36.1934', sector3 = '35.8702', fastestLap = '107.2728', grid = 0"
string(343) "INSERT INTO results SET compId = 8, eventId = 934, eventSession = 'P', driverId = 621, teamId = 308, position = 10, raceTime = '', laps = 12, pitstops = 0, engine = 51, tyres = '4', sector1 = '35.2224', sector2 = '36.0565', sector3 = '36.3339', fastestLap = '107.6127', grid = 0"
string(342) "INSERT INTO results SET compId = 8, eventId = 934, eventSession = 'P', driverId = 447, teamId = 232, position = 11, raceTime = '', laps = 9, pitstops = 0, engine = 57, tyres = '4', sector1 = '35.1237', sector2 = '36.2297', sector3 = '36.2870', fastestLap = '107.6404', grid = 0"
但是,当不在调试中时,这仅针对集合中的第一条记录运行。无论我输入什么数据集。
我无法解释出现问题或是否有任何事情在第一个实例(正确输入)后停止脚本。
注意:原始代码不是我的,当他离开我们的小组时,我不再能够访问原始开发人员,所以我只是基于当前的信息。如前所述,此脚本在昨晚之前一直正常运行,并且未对可能影响它的代码的其他部分进行任何更改。
感谢您的帮助!
编辑:这是整个循环,如评论中所要求的那样:
private function queryDb()
{
$year=gmdate("Y");
// What $this->data holds at this point is an array with all drivers, positions, times, etc
// using ['driver'][0] => Jim Parisis that correspond to ['position'][0] => 1 and the ['bestTime'][0] => 95.9577 and so on
// Let's pick the event Id from $this->data
$eventId = $this->data['event'];
$eventsession = $this->data['evsess'];
// instantiate the finances class
// So we can use later any of its method like $finances->makeSomething($argument)
$finances = new Finances($eventId, $this->debug);
// Let's get the competition holding that event
$query = "SELECT competition FROM ".$this->dbName.".calendar WHERE id='$eventId'";
$result = mysql_query($query);
// $comp_id = mysql_fetch_row($result); // What you have there is an array array(1) { [0]=> string(1) "1" }
// That's true that competition is 1 but having in array you have to access it like $comp_id[0]
while ($row = mysql_fetch_row($result))
$comp_id = (int)$row[0]; // Better build it as simple integer to save memory
mysql_free_result($result);
// echo '<pre>'; print_r($this->data); echo '</pre>';
$i = 0; // Let's build some integer to play with because we have keys starting at 0 in the $this->data array
foreach ($this->data['drivers']['name'] as $key => $value) {
$driverFullName = $value; // now the foreach goes for each element of the 'drivers' key storing it in the $value variable
// Gets the users id
$query = "SELECT id FROM ".$this->dbName.".users WHERE CONCAT(firstName,' ',lastName) ='".$driverFullName."'";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
$driverid = $row[0];
mysql_free_result($result);
//var_dump($driverid);
// Gets the partA from contracts
$teamid = NULL;
if ($comp_id==10) { $teamid= 0; }
else {
$query = "SELECT partA FROM ".$this->dbName.".contracts WHERE partB ='".$driverid."' AND competition ='".$comp_id."' AND curState ='A'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 0) {
while ($row = mysql_fetch_row($result))
$teamid = $row[0];
}
else { $teamid=0; echo "Warning: driver $driverFullName has no contract."; }
mysql_free_result($result);
}
//var_dump($teamid);
// Gets the engine
// We can wrap this and the next queries in just one by using LEFT JOIN but that's another story
$enginemodel = NULL;
$engineId = NULL;
/*$query = "SELECT te.engine as engineId, e.engine as engineModel, en.id as engineId2 FROM DCO_team_engines te LEFT JOIN DCO_engines e ON te.engine=e.id LEFT JOIN engines en ON en.brand=e.engine WHERE te.team ='".$teamid."' AND te.comp='".$comp_id."' AND te.year ='".$year."'";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
$engineid = $row[2];
mysql_free_result($result);*/
//Substitute engine
$query = "SELECT engine FROM ".$this->dbName.".DCO_team_engines WHERE team ='".$teamid."' AND comp ='".$comp_id."' AND year ='".$year."'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 0) {
while ($row = mysql_fetch_row($result))
$engineId = $row[0];
}
mysql_free_result($result);
$query = "SELECT vehchoice FROM ".$this->dbName.".competitions WHERE id ='".$comp_id."'";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
$vehchoice = $row[0];
mysql_free_result($result);
if ($vehchoice==1) {
$query = "SELECT classes FROM ".$this->dbName.".licenses WHERE competition ='".$comp_id."' AND applicantId ='".$teamid."' AND concept ='2' AND validDate='".$year."'";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
$engineId = $row[0];
mysql_free_result($result);
}
//var_dump($engineId); echo '<br>';
// $this->data['sectors']['s1'][] = $sector1;
// $this->data['sectors']['s2'][] = $sector2;
// $this->data['sectors']['s3'][] = $sector3;
$sector1 = $this->data['sectors']['s1'][$i];
$sector2 = $this->data['sectors']['s2'][$i];
$sector3 = $this->data['sectors']['s3'][$i];
$laps = $this->data['drivers']['laps'][$i];
$position = $this->data['drivers']['position'][$i];
$finishstatus = $this->data['drivers']['finishStatus'][$i];
$untimed = $this->data['drivers']['untimed'][$i];
$carnumber = $this->data['drivers']['carnumber'][$i];
if ($finishstatus=='Finished Normally') { $racetime = $this->data['drivers']['finishTime'][$i]; }
if ($finishstatus=='DNF') { $racetime = "DNF"; }
$grid = 0; // grid is always empty until the following condition applies
if ($eventsession=='R' || $eventsession=='R1' || $eventsession=='R2' || $eventsession=='R3') {
$laprank = $this->data['drivers']['fastestlaprank'][$i];
$grid = $this->data['drivers']['gridpos'][$i];
}
if ($engineId == null)
$engineId = 'DEFAULT';
if ($comp_id=='12') { $carchosen = $this->data['drivers']['team'][$i];
$query = "SELECT id FROM ".$this->dbName.".available_vehicles WHERE label ='".$carchosen."'";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
$engineId = $row[0];
mysql_free_result($result);
}
$query = "INSERT INTO results SET
compId = ".$comp_id.",
eventId = ".$eventId.",
eventSession = '".$eventsession."',
driverId = ".$driverid.",
teamId = ".$teamid.",
position = ".$this->data['drivers']['position'][$i].",
raceTime = '".$racetime."',
laps = ".$this->data['drivers']['laps'][$i].",
pitstops = ".$this->data['drivers']['pitstops'][$i].",
engine = ".$engineId.",
tyres = '4',
sector1 = '".$sector1."',
sector2 = '".$sector2."',
sector3 = '".$sector3."',
fastestLap = '".$this->data['drivers']['bestTime'][$i]."',
grid = ".$grid;
// If debug is true then just var_dump but don't execute query
if ($this->debug) {
var_dump($query); echo '<br>';
}
else { // debug is false here, then not debug and run mysql query as usual
mysql_query($query);
}
// Ok, if you need to call fines method within the loop
// call it here, for example to insert rows depending on the driver values like laps, pitstops, etc.
// Notice we parse the whole array
$query = "SELECT careerLadder, usesManagement, vehchoice, monoEngine FROM ".$this->dbName.".competitions WHERE id='$comp_id'";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$careerLadder = (int)$row[0]; // Better build it as simple integer to save memory
$usesManagement = (int)$row[1];
$vehchoice = (int)$row[2];
$monoEngine = (int)$row[3];
}
mysql_free_result($result);
if ($comp_id!=10)
{
if (($eventsession!='T')&&($eventsession!='P')&&($eventsession!='Q'))
{
$finances->standings($comp_id,$position, $driverid, $year, $teamid, $eventsession, $laps);
$finances->standingsarrange($comp_id);
}
}
if ($usesManagement==1)
{
$finances->ladderfinances($teamid, $comp_id, $eventsession, $position, $laprank,$laps);
}
if ($comp_id==1)
{
if ($eventsession=='T')
{
$finances->rdpoints($teamid,$comp_id,$laps,$untimed);
$finances->erdpoints($teamid,$comp_id,$laps,$untimed);
}
if (($eventsession!='T')&&($eventsession!='P'))
{
$finances->enginewear($driverid,$teamid,$laps,$carnumber);
}
}
$i++; // ok let's go to the next element if any, if foreach notices it's the last then it stops :)
}
$finances->standingstiebreak($comp_id);
//if ($dom->getElementsByTagName('Qualify')->item(0))
// $this->data['session'] = $dom->getElementsByTagName('Qualify')->item(0)->nodeName;
//if ($dom->getElementsByTagName('Practice1')->item(0))
// $this->data['session'] = $dom->getElementsByTagName('P')->item(0)->nodeName;
if ($eventsession=='T') { $session = "Test"; }
if ($eventsession=='P') { $session = "Practice"; }
if ($eventsession=='Q') { $session = "Qualifying"; }
if ($eventsession=="R") { $session = "Race"; }
if ($eventsession=='R1') { $session = "Race 1"; }
if ($eventsession=='R2') { $session = "Race 2"; }
if ($eventsession=='R3') { $session = "Race 3"; }
echo "<h2>$session results entered successfully</h2>";
答案 0 :(得分:0)
问题已解决 - 我们尝试添加行的数据库将ID字段设置为smallint。我们实际上达到了行的限制(65535),因此它正在调试而不是在现实生活中。