I'm trying to get an xml file from an ftp and then insert select data into mysql db. I'm shooting in the dark but from googling this is what i've tried so far:

   $curl = curl_init();
    $file = fopen("import.xml", 'w');
    curl_setopt($curl, CURLOPT_URL, "ftp://company@company.company.se/company/import.xml"); #input
    curl_setopt($curl, CURLOPT_FILE, $file); #output
    curl_setopt($curl, CURLOPT_USERPWD, "$_FTP[user]:$_FTP[password]");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $testcurl = curl_exec($curl);

    curl_close($curl);

    $xml = simplexml_load_file($testcurl);

foreach($xml->loanaccount as $mess){

$account_number= mysql_real_escape_string($mess->account_number);
$main= mysql_real_escape_string($mess->main);

//insert into databse                     
mysql_query("INSERT INTO account (account_number, main)
VALUES ('$account_number', '$main')")
or die(mysql_error());

echo "inserted into mysql<br /><br />";

//show updated records            
printf ("Records inserted: %d\n", mysql_affected_rows());  
}

This is the output I get:

connected to DB

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "" in /www/webvol11/kh/ezjvt3700zfmb4q/company.se/public_html/service/test1.php on line 29

Warning: Invalid argument supplied for foreach() in /www/webvol11/kh/ezjvt3700zfmb4q/company.se/public_html/service/test1.php on line 30

Recommended Answers

All 3 Replies

Can you check what $testcurl contains? I've read that there may be an issue if the FTP server requires PASV. Check some of the CURLOPT_FTP_xxx options.

Thanks for your reply!

I almost got it now, however i'm wondering if it's possible to make the foreach statement conditional.

I tried to insert this $gid = $mess->account->{'tenor'};if ( $gid == "nytt" ) { after the foreach statement but to now avail.

    foreach($xml->loanaccount as $mess){
       $gid = $mess->account->{'tenor-type'};
            if ( $gid == "nytt" ) {
               $account_number= mysql_real_escape_string($mess->account_number);
               $main= mysql_real_escape_string($mess->main);
           //insert into databse                     
             mysql_query("INSERT INTO account (account_number, main)
            VALUES ('$account_number', '$main')")
         or die(mysql_error());
            echo "inserted into mysql<br /><br />";
           //show updated records            
          printf ("Records inserted: %d\n", mysql_affected_rows());  
        }
}

Any thoughts?

I decided to skip the if statement so all is well :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.