We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,913 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

curl->simplexml_load_file->mysql

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

2
Contributors
3
Replies
1 Week
Discussion Span
3 Months Ago
Last Updated
5
Views
Question
Answered
adishardis
Junior Poster in Training
91 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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.

pritaeas
Posting Prodigy
Moderator
9,276 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,457
Skill Endorsements: 86

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?

adishardis
Junior Poster in Training
91 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

adishardis
Junior Poster in Training
91 posts since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 3 Months Ago by pritaeas

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.5350 seconds using 2.67MB