XML TO数据库插入

时间:2012-02-04 05:34:17

标签: php mysql xml

我正在使用ftp连接从一个站点检索数据,然后将该数据存储在我的服务器上

导入的数据采用ZIp格式

首先提取该数据,然后将zip和xml文件存储在我的服务器上 然后来自该xml文件的数据在数据库中进行扫描

除了数据库存储

之外,一切都很顺利

XML文件中的数据未存储在我的DAtabase中

这是我的代码

<?php
mysql_connect("localhost","dbname","password");
mysql_select_db("dbname");
$conn = ftp_connect("ftpname") or die("Could not connect");//create connection.

ftp_login($conn,"ftpusername","ftppassword");//login.

$files_list_at_server = ftp_nlist($conn,"/FEEDER/News/Equity Market News/");//list of current files on server.

$files_at_server=array();
foreach($files_list_at_server as $a)
{
array_push($files_at_server,basename($a));//pushing the file names in a array.
}


$current_dir_files = scandir("equitymarketnews");//list the present files in the dir.

$array = array_diff($files_at_server,$current_dir_files);//different files which are on server and not on our folder.

foreach($array as $q)
{
 ftp_get($conn,"equitymarketnews/$q","/FEEDER/News/Equity Market News/$q",FTP_BINARY); //downloads the files.

 $zip = zip_open("equitymarketnews/$q");

   if ($zip)
    {
     while ($zip_entry = zip_read($zip))
      {
       $zname = zip_entry_name($zip_entry);

       if (zip_entry_open($zip, $zip_entry))
         {  
          $zip_fs=zip_entry_filesize($zip_entry);
          $zz = zip_entry_read($zip_entry,$zip_fs);

          $z=fopen("equitymarketnews/$zname","w");
          fwrite($z,$zz);
          fclose($z);
        //  $sql1 = "TRUNCATE TABLE `bod`";
        //  mysql_query($sql1);

      $sql = "LOAD DATA LOCAL INFILE 'equitymarketnews/$zname' INTO TABLE `equitymarketnews` FIELDS TERMINATED BY '|' LINES STARTING BY '<row>' TERMINATED BY '</row>' (`ByLine`,`StoryId`,`PublishDate`,`Author`,`Category`,`SubCategory`,`TitleLine`,`SubTitleLine`,`StoryMain`,`Flag`)";
                mysql_query($sql);
                echo mysql_error(); 

          zip_entry_close($zip_entry);
         }
 }}
zip_close($zip);
}
ftp_close($conn);
?>

0 个答案:

没有答案