Guest User

Untitled

a guest
Dec 8th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "bui";
  7.  
  8. $typeids=array(34,35);
  9. $url="http://api.eve-central.com/api/marketstat?regionlimit=10000002&typeid=".join('&typeid=', $typeids);
  10. $ch = curl_init($url);
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12. curl_setopt($ch, CURLOPT_HEADER, 0);
  13. $data = curl_exec($ch);
  14. if($data === false)
  15. {
  16. echo 'Curl error: ' . curl_error($ch);
  17. }
  18. else
  19. {
  20. curl_close($ch);
  21. }
  22.  
  23. $xml =new SimpleXMLElement($data);
  24.  
  25. foreach($typeids as $typeid){
  26. $item=$xml->xpath('/evec_api/marketstat/type[@id='.$typeid.']');
  27. $price= (float) $item[0]->sell->percentile;
  28. $price=round($price,2);
  29. }
  30.  
  31. $types = implode(" ",$typeids);
  32.  
  33. mysqli_report(MYSQLI_REPORT_ALL); // Traps all mysqli error
  34.  
  35. try {
  36. // code that may fail here
  37. // Create connection
  38. $conn = new mysqli($servername, $username, $password, $dbname);
  39.  
  40. // Check connection
  41. if ($conn->connect_error) {
  42. die("Connection failed: " . $conn->connect_error);
  43. }
  44.  
  45. $stmt = $conn->prepare("INSERT INTO `item_prices` (`itemid`, `price`) VALUES (?,?) ON DUPLICATE KEY UPDATE `itemid`= VALUES (?)");
  46.  
  47. $stmt->bind_param('sd', $types, $price);
  48. $stmt->execute();
  49.  
  50. echo "New records created successfully";
  51.  
  52. $stmt->close();
  53. $conn->close();
  54.  
  55. } catch (\Exception $e) {
  56. echo $e;
  57. }
  58.  
  59.  
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment