我的 XML:
<simpletype type="TURKEY">
<city code="01">
<telcode>(0 322)</telcode>
<name>Adana</name>
<time>1345337940</time>
</city>
<city code="02">
<telcode>(0 416)</telcode>
<name>Adıyaman</name>
<time>1340236800</time>
</city>
</simpletype>
MY mysql导入代码:
require_once('db.php');
@mysql_connect(_SERVER,_USER,_PASSWORD);
@mysql_select_db(_DATABASE);
$doc = new DOMDocument();
$doc->load( 'CityCode.xml' );
$cities = $doc->getElementsByTagName( "city" );
foreach( $cities as $city )
{
$names = $city->getElementsByTagName( "name" );
$codes = $city->getElementsByTagName( "telcode" );
$times = $city->getElementsByTagName ( "time");
$name = $names->item(0)->nodeValue;
$code = $codes->item(0)->nodeValue;
$time = $times->item(0)->nodeValue;
mysql_query("SET CHARACTER SET utf8");
$sql = "INSERT INTO telcode (sehir, name, time) VALUES ('$name' ,'$code' ,'UNIX_TIMESTAMP ($time') ";
@mysql_query($sql);
}
我的问题:我的 xml 源有一个 unix 时间戳,我必须使用 mysql 时间戳 (0000-00-00 00:00:00) 如何将 $time unix 时间戳转换为 mysql 时间戳并记录 mysql db?