php - 将 XML 文件中的数据插入 MySql DB

标签 php mysql xml import

你好,我遇到了一些问题,这里是 我必须加载具有超过 2000 个属性的 xml 文件,在这里您可以找到文件的结构

http://admin.resales-online.com/live/Resales/Export/CreateXMLFeed.asp?U=RESALES@MOVE2S&P=KKPDRT6986NG&n=1

我正在使用以下代码

<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>

我收到了这个错误

错误

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行 '' 附近使用的正确语法

如果有人知道可能是什么问题,请在这里回答我:)

谢谢

最佳答案

这是 INSERT 的格式:

INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);

VALUES 的左括号和右括号在哪里?

关于php - 将 XML 文件中的数据插入 MySql DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16945342/

相关文章:

PHP日期时间转换保存到MySQL

php - 复杂的 MySQL 表模式及其性能

android - 通过 LAN 连接到 mySQL 数据库而不使用网络服务器

android - 如何在android中调整复选框图像的大小?

c# - WriteStartDocument 编写的错误 XML 编码标记

xml - 报表标题与页面内容的表格重叠

javascript - Yii,在提交按钮上附加一个 javascript 函数

php - 为什么在 php 和 html 中编码时 else body 不起作用

php - 从 laravel 将 DOB 插入 mysql

javascript - 根据其他表单字段填写选择选项输入