我試圖在我的數據庫中使用php獲取XML文件的內容到表中。XML沒有正確插入到mysql
這幾乎是XML文件的要點。
<Meet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.nspace.co.za/">
<Name>Test Meet 1</Name>
<StartDate xsi:nil="true" />
<EndDate xsi:nil="true" />
<MeetId>168</MeetId>
<CustomerId>37</CustomerId>
<DatabaseId>3</DatabaseId>
<EventList>
<Event>
<CustomerId>37</CustomerId>
<DatabaseId>3</DatabaseId>
<EventId>1111</EventId>
<Name>Formation Skydiving 2-Way - Open 168</Name>
<EventTeamList>
<EventTeam>
<CustomerId>37</CustomerId>
<DatabaseId>3</DatabaseId>
<EventTeamId>00bab00</EventTeamId>
<Name>201 - Test Team 2</Name>
<NationAbbreviation />
<Position>1</Position>
<TotalScore>51.00</TotalScore>
</EventTeam>
<EventTeam>
<CustomerId>37</CustomerId>
<DatabaseId>3</DatabaseId>
<EventTeamId>0001</EventTeamId>
<Name>202 - Test Team 9</Name>
<Position>2</Position>
<TotalScore>41.00</TotalScore>
</EventTeam>
<EventTeam>
<CustomerId>37</CustomerId>
<DatabaseId>3</DatabaseId>
<EventTeamId>0001</EventTeamId>
<Name>204 - Test Team 7</Name>
<Position>2</Position>
<TotalScore>31.00</TotalScore>
</EventTeam>
</EventTeamList>
</Event>
</EventList>
</Meet>
這是我的PHP:
$mdstring = file_get_contents('detail' . $meet->MeetId . '.xml');
$meetdetails = new SimpleXMLElement($mdstring);
if($mdstring){
foreach($meetdetails->EventList->Event as $event)
{
mysqli_query($con,"INSERT IGNORE INTO events (event_id, meet_id, event_name)
VALUES ('{$event->EventId}', '{$meet->MeetId}', '{$event->Name}')");
foreach($event->EventTeamList->EventTeam as $eventTeam)
{
mysqli_query($con,"INSERT IGNORE INTO event_teams (team_id, event_id, meet_id, team_name)
VALUES ('{$eventTeam->EventTeamId}', '{$event->EventId}', '{$meet->MeetId}', '{$eventTeam->Name}')");
}
}
}
幾乎所有的東西插入細末,用的標籤EventTeamId的內容外,由於某種原因,它只是從0
和自動遞增開始team_id
列。我不能爲我的生活找出原因,我以相同的方式插入的其他數據,$eventTeam->Name
,工作得很好。
任何想法?
謝謝。
啓用的error_reporting,並做一些適當的調試。 – CBroe