我在将数据从 xml 导入 SQL 表时遇到问题。xml 看起来像这样:
<MeasuringPoints>
<MeasuringPoint ID="BaseStation" LastChange="2013-05-20T12:15:03.837">
</MeasuringPoint>
<MeasuringPoint ID="MiddleStation" LastChange="2012-08-01T11:47:33.160">
</MeasuringPoint>
<MeasuringPoint ID="MountainStation" LastChange="2013-05-20T12:15:03.840>
</MeasuringPoint>
</MeasuringPoints>
使用php(foreach
循环)
foreach($skiarea->MeasuringPoints->MeasuringPoint as $measuring) {
$MEASURING_POINTS = $measuring['ID'];
$MEASURING_LAST_CHANGE = $measuring['LastChange'];
}
我得到这个输出数据:
BaseStation - 1369052103
MiddleStation - 1343821653
MountainStation - 1369052103
我正在尝试将该值插入到 batabase
mysql_query("
INSERT INTO database_name SET
base_station_last_change = '$MEASURING_LAST_CHANGE[0]',
middle_station_last_change = '$MEASURING_LAST_CHANGE[1]',
mountain_station_last_change = '$MEASURING_LAST_CHANGE[2]',
") OR die(mysql_error());
但是这段代码不起作用。只导入一个值。
如何将这些数据插入到 sql 数据库字段中?