Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "bui";
- $typeids=array(34,35);
- $url="http://api.eve-central.com/api/marketstat?regionlimit=10000002&typeid=".join('&typeid=', $typeids);
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- $data = curl_exec($ch);
- if($data === false)
- {
- echo 'Curl error: ' . curl_error($ch);
- }
- else
- {
- curl_close($ch);
- }
- $xml =new SimpleXMLElement($data);
- foreach($typeids as $typeid){
- $item=$xml->xpath('/evec_api/marketstat/type[@id='.$typeid.']');
- $price= (float) $item[0]->sell->percentile;
- $price=round($price,2);
- }
- $types = implode(" ",$typeids);
- mysqli_report(MYSQLI_REPORT_ALL); // Traps all mysqli error
- try {
- // code that may fail here
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $stmt = $conn->prepare("INSERT INTO `item_prices` (`itemid`, `price`) VALUES (?,?) ON DUPLICATE KEY UPDATE `itemid`= VALUES (?)");
- $stmt->bind_param('sd', $types, $price);
- $stmt->execute();
- echo "New records created successfully";
- $stmt->close();
- $conn->close();
- } catch (\Exception $e) {
- echo $e;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment