Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: Titus Louage
- * Date: 08-May-18
- * Time: 11:31
- */
- class Hearthstonedb
- {
- private static $hearthstone = null;
- private $db;
- private function __construct()
- {
- try
- {
- $config = Config::getConfigInstantie();
- $server = $config->getServer();
- $database = $config->getDatabase();
- $username = $config->getUsername();
- $password = $config->getPassword();
- $this->db = new PDO("mysql:host=$server; dbname=$database; charset=utf8mb4",
- $username,
- $password,
- array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
- }
- catch (PDOException $e)
- {
- die($e->getMessage());
- }
- }
- public static function getHearthstonedb()
- {
- if(is_null(self::$hearthstone))
- {
- self::$hearthstone = new Hearthstonedb();
- }
- return self::$hearthstone;
- }
- public function updatebd()
- {
- $jsondata = file_get_contents('minions.json');
- $obj = json_decode($jsondata);
- $i = 0;
- foreach ($obj as $card){
- $i++;
- if (isset($card->dbfId)){
- $id = $card->dbfId;
- }else{
- $id = null;
- }
- if(isset($card->name)){
- $name = $card->name;
- }else{
- $name = null;
- }
- if(isset($card->cardSet)){
- $set = $card->cardSet;
- }else{
- $set = null;
- }
- if(isset($card->type)){
- $type = $card->type;
- }else{
- $type = null;
- }
- if (isset($card->text)){
- $text = $card->text;
- }else{
- $text = null;
- }
- if(isset($card->cost)){
- $cost = $card->cost;
- }else{
- $cost = 0;
- }
- if(isset($card->attack)){
- $attack = $card->attack;
- }else{
- $attack = null;
- }
- if(isset($card->health)){
- $health = $card->health;
- }else{
- $health = null;
- }
- if(isset($card->playerClass)){
- $class = $card->playerClass;
- }else{
- $class = 'neutral';
- }
- if(isset($card->img)){
- $img = $card->img;
- }else{
- $img = null;
- }
- $battlecry = 0;
- $charge = 0;
- $deathrattle = 0;
- $divineShield = 0;
- $poison = 0;
- $stealth = 0;
- $taunt = 0;
- $spellDamage = 0;
- $windfury = 0;
- $aura = 0;
- $silence = 0;
- $adjacentBuff = 0;
- if (isset($card->mechanics)){
- $mechanics = $card->mechanics;
- foreach ($mechanics as $mechanic){
- switch ($mechanic->name){
- case 'Battlecry':
- $battlecry = 1;
- break;
- case 'Charge':
- $charge = 1;
- break;
- case 'Deathrattle':
- $deathrattle = 1;
- break;
- case 'Divine Shield':
- $divineShield = 1;
- break;
- case 'Poisonous':
- $poison = 1;
- break;
- case 'Stealth':
- $stealth = 1;
- break;
- case 'Taunt':
- $taunt = 1;
- break;
- case 'Spell Damage':
- $spellDamage = 1;
- break;
- case 'Windfury':
- $windfury = 1;
- break;
- case 'Aura':
- $aura = 1;
- break;
- case 'Silence':
- $silence = 1;
- break;
- case 'AdjacentBuff':
- $adjacentBuff = 1;
- break;
- default:
- var_dump('piemel');
- var_dump($mechanic);
- break;
- }
- }
- }
- //var_dump("INSERT INTO cards VALUES (".$id.", '".$name."', '".$set."', '".$type."', '".$text."', ".$cost.", ".$attack.", ".$health.", '".$class."', '".$img."', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE);");
- try {
- $sql = "INSERT INTO cards VALUES (:id, :name, :set, :type, :text, :cost, :attack, :health, :class, :img);INSERT INTO mechanics VALUES (:id, $aura, $adjacentBuff, $battlecry, $charge, $deathrattle, $divineShield, $poison, $stealth, $taunt, $spellDamage, $silence, $windfury)";
- var_dump($sql);
- $stmt = $this->db->prepare($sql);
- $stmt->bindParam(':id', $id);
- $stmt->bindParam(':name', $name);
- $stmt->bindParam(':set', $set);
- $stmt->bindParam(':type', $type);
- $stmt->bindParam(':text', $text);
- $stmt->bindParam(':cost', $cost);
- $stmt->bindParam(':attack', $attack);
- $stmt->bindParam(':health', $health);
- $stmt->bindParam(':class', $class);
- $stmt->bindParam(':img', $img);
- $stmt->execute();
- }catch (PDOException $e){
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement