我在PHP中使用simple_load_file读取XML标记并导致导入XML文件数据库错误
如何使用php
在数据库中导入XML文件ini_set('display_errors','On');
echo "starting";
//mysql connection
$con2 = mysql_connect("localhost","root","root");
if (!$con2) {
die('Could not connect: ' . mysql_error());
}
$selectdb = mysql_select_db("weberpdemo", $con2);
if (!$selectdb) {
die('Database not used: ; ' . mysql_error());
}
echo "connected to DB<br /><br />";
examples given $mess = simplexml_load_file($filename);
echo "xml loaded<br /><br />";
$messageid = mysql_real_escape_string($mess->messageid);
$mobile = mysql_real_escape_string($mess->mobile);
$time = mysql_real_escape_string($mess->time);
$latitude = mysql_real_escape_string($mess->latitude);
$longitude = mysql_real_escape_string($mess->longitude);
$status = mysql_real_escape_string($mess->status);
$speed = mysql_real_escape_string($mess->speed);
$address = mysql_real_escape_string($mess->address);
$direction = mysql_real_escape_string($mess->direction);
$runningodo = mysql_real_escape_string($mess->runningodo);
echo "xml parsed<br /><br />";
//insert into databse
mysql_query("INSERT INTO xml (messageid, mobile, time, latitude, longitude, status, speed, address, direction, odometer)
VALUES ('$messageid', '$mobile', '$time', '$latitude', '$longitude', '$status', '$speed', '$address', '$direction', '$runningodo')")
or die(mysql_error());
答案 0 :(得分:2)
取决于您在导入数据库后尝试使用数据存档的内容。