[英]Insert data from XML file into MySql DB
Hello i got problem with something, here it is i have to load xml file which has over 2000 properties, here you can find the structure of the file 您好,我遇到了一些问题,这是我必须加载具有2000多个属性的xml文件,在这里您可以找到文件的结构
http://admin.resales-online.com/live/Resales/Export/CreateXMLFeed.asp?U=RESALES@MOVE2S&P=KKPDRT6986NG&n=1 http://admin.resales-online.com/live/Resales/Export/CreateXMLFeed.asp?U=RESALES@MOVE2S&P=KKPDRT6986NG&n=1
and i'm using the fallowing code 我正在使用休闲代码
<html>
<head>
<title>Insert Record</title>
</head>
<body>
<?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(-1);
include ('config.php');
$url = "http://admin.resales-online.com/live/Resales/Export/XMLFeed.asp?U=RESALES@MOVE2S&P=KKPDRT6986NG&n=100";
try{
$xml = new SimpleXMLElement($url, null, true);
}catch(Exception $e){
echo $e->getMessage();
exit;
}
$sql = 'INSERT INTO properties (`id`,`status_date`,`status`,`listed_date`,`last_updated`,`price`,`currency`,`country`,`province`) VALUES ';
foreach($xml->property as $property){
$sql .= sprintf("\n",
mysql_real_escape_string($property->id),
mysql_real_escape_string($property->status_date),
mysql_real_escape_string($property->listed_date),
mysql_real_escape_string($property->last_updated),
mysql_real_escape_string($property->price),
mysql_real_escape_string($property->currency),
mysql_real_escape_string($property->country),
mysql_real_escape_string($property->province)
);
}
$sql = rtrim($sql, ',') . ';';
if(!mysql_query($sql)){
echo '<h1 style="color: red;">Error</h1><p>', mysql_error(), '</p>';
}
?>
</body>
</html>
and i got this error 我得到这个错误
Error 错误
You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
检查与您的MySQL服务器版本相对应的手册,以在第1行的''附近使用正确的语法
Please if anyone knows what might be the problem answer me here :) 如果有人知道可能是什么问题,请在这里回答我:)
Thank you 谢谢
This is the format for an INSERT: 这是INSERT的格式:
INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
Where are your opening and closing parentheses for VALUES? VALUES的左括号和右括号在哪里?
Each of the values in the query are missing single quotes, and you're missing the opening and closing parenthesis. 查询中的每个值都缺少单引号,并且您缺少左括号和右括号。 The proper syntax for an INSERT is:
INSERT的正确语法是:
INSERT INTO `table` (`field1`, `field2`, `field3`) VALUES ('value1', 'value2', 'value3')
Yours will look more like: 您的看起来会更像:
INSERT INTO `table` (`field1`, `field2`, `field3`) VALUES value1, value2, value3
The easiest way to debug is to echo out your $sql
varaible so you can see what it looks like so you can quickly spot obvious errors. 调试的最简单方法是回显
$sql
变量,以便查看其外观,以便快速发现明显的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.