Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将XML文件中的数据插入MySql数据库_Php_Mysql_Xml_Import - Fatal编程技术网

Php 将XML文件中的数据插入MySql数据库

Php 将XML文件中的数据插入MySql数据库,php,mysql,xml,import,Php,Mysql,Xml,Import,你好,我有点问题,给你 我必须加载具有2000多个属性的xml文件,在这里您可以找到文件的结构 我用的是休闲代码 <html> <head> <title>Insert Record</title> </head> <body> <?php ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__F

你好,我有点问题,给你 我必须加载具有2000多个属性的xml文件,在这里您可以找到文件的结构

我用的是休闲代码

<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 INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);

值的开始括号和结束括号在哪里?

查询中的每个值都缺少单引号,并且缺少开始括号和结束括号。插入的正确语法为:

INSERT INTO `table` (`field1`, `field2`, `field3`) VALUES ('value1', 'value2', 'value3')
您的将看起来更像:

INSERT INTO `table` (`field1`, `field2`, `field3`) VALUES value1, value2, value3

调试最简单的方法是回响你的<代码> $SQL <代码> MySQL**<代码>函数列表被禁止,请考虑在代码中使用<代码> MySQLI< /COD>或<代码> PDO对象。否则,当升级PHP版本时,您可能会面临代码中断的风险。我更改了一些$sql。=sprintf(“\n(%s)”在上面的代码中现在没有$s,当我尝试回显sql时,它将此NSERT显示为属性(

id
)值(R188242)…以及错误您的SQL语法中有错误;请查看与您的MySQL服务器版本对应的手册,以了解可使用的正确语法(R188246)(R188293)(R188310)(R188314)(R188318)(R188329)(R188349)(R188393)'在第3行,但当我将数据库中的id设置为int时,id的代码比id的代码更有效,然后它以1到100的数字添加到数据库中,但当我更改为string时,我现在无法添加它们。.字符串有点问题,我认为int type可以在没有引号的情况下工作,但字符串需要用引号包装。