mysql - Importing XML and Skipping Errors (PHP) -


i have cron job runs each night update our stock system (from external source) via multiple xml files.

however, case, errors appear in xml (nothing can - 3rd party provides this).

when error occur, script comes stop , no more files processed. there way if error encountered, remaining files still imported?

here code:

<?php include 'connect.php';    $sql = "delete stock allow_keep!='1'"; mysql_query($sql);  //clear stock table loop through , add active users   $query = "select * users active='1'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){    $xml = simplexml_load_file(“users/xml_file_”.$row['id'].".xml");  foreach($xml->children() $child) {   $myquery="replace stock set  stockid='" . $child->stockid .  "', make='" . addslashes($child->make) .  "', model='" . addslashes($child->model) .  "', image='" . $child->image_url_1 .  "', details='" . addslashes($child->description) .  "', price='" . $child->price .  "'";  $result2=mysql_query($myquery) or die(mysql_error());         }  }   ?> 

appreciate can this!

if it's simplexml 1 interrupting process, tell deal errors internally instead of outputting them

libxml_use_internal_errors(true);  $xml = simplexml_load_file(“users/xml_file_”.$row['id'].".xml"); if($xml) {     // format fine, try load it. } else {     // leave in error log or } 

if it's mysql, can wrap replace query in try / catch block.

btw, don't use mysql functions. use mysqli or (better yet) pdo functions. if you're afraid of learning curve, start pdo::exec, it's not elegant part of pdo it's practically drop in replacement if you're used manually make queries variable interpolation.

try aim build prepared queries in mid term, pay off tenfold.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -