I'm trying to write all iteam names and prices to database but I don't know why ★
is replaceing in database to ★
example ★ Bayonet
to ★ Bayonet
I know code maybe is bad becouse I'm beginner
cost.json looks like these:
{
"status" : "success",
"prices" : [
{
"market_hash_name" : "★ Bayonet",
"price" : "147.41",
"created_at" : 1453784357
},
{
"market_hash_name" : "★ Bayonet | Blue Steel (Battle-Scarred)",
"price" : "112.28",
"created_at" : 1453784518
}, ...
Here are my code that I'm using:
<?php
@include_once ("pdocon.php");
$url = 'cost.json';
$api = file_get_contents($url);
$json = json_decode($api, true);
foreach($json['prices'] as $item) {
$itemname = $item['market_hash_name'];
$itemcost = $item['price'];
$stmt = $dbh->prepare("SELECT * FROM items WHERE name=?");
$stmt->execute(array($itemname));
$rs = $stmt->fetch(PDO::FETCH_ASSOC);
if(!empty($rs)) {
if(time()-$rs["lastupdate"] < 604800) die($rs["cost"]);
}
$stmt = $dbh->prepare("UPDATE items SET `cost` = ?,`lastupdate` = ? WHERE `name` = ?");
$stmt->execute(array($itemcost, time(), $itemname));
$stmt = $dbh->prepare("INSERT INTO items (`name`,`cost`,`lastupdate`) VALUES (?, ?, ?)");
$stmt->execute(array($itemname, $itemcost, time()));
}
?>