Results 1 to 2 of 2

Thread: Storing warlog to database

  1. #1

    Storing warlog to database

    The following code does not write the warlog information to databse :

    PHP Code:
    #!/usr/bin/php
    <?php

    parse_str
    (implode('&'array_slice($argv1)), $_GET);
    $clantag $_GET['clantag'];

    chdir("/var/www/virtual/aremorica-online.de/htdocs/update/");

    include 
    "../token_wars.php";
    include 
    "../mysql_coc.php";

    $url "https://api.clashofclans.com/v1/clans/" urlencode($clantag) . "/warlog";

    $curl curl_init($url);
    $header = array();
    $header[] = "Accept: application/json";
    $header[] = "Content-type: text/html; charset=UTF-8";
    $header[] = "Authorization: Bearer ".$api_token;
    curl_setopt($curlCURLOPT_HTTPHEADER$header);
    curl_setopt($curlCURLOPT_SSL_VERIFYHOSTfalse);
    curl_setopt($curlCURLOPT_SSL_VERIFYPEERfalse);
    curl_setopt($curlCURLOPT_RETURNTRANSFER1);
    $curl_result curl_exec($curl);
    $war_items json_decode($curl_resulttrue);
    curl_close($curl);

    if (isset(
    $war_item["reason"])) {
        
    $error true;
        echo 
    $war_item["reason"];
        echo 
    "\n";
    }

    include 
    "../mysql_coc.php";

    $wars $war_items['items'];
    foreach (
    $wars as $war)
        {
            
    $war_sql  "SET @result = '" $war["result"];
            
            
    $eT date_create_from_format('Ymd\THis\.\0\0\0\Z',$war["endTime"]);
            
    $endTime $eT->format('Y-m-d H:i:s');
            
    $war_sql .= "', @endTime=STR_TO_DATE('" $endTime "', '%Y-%m-%d %H:%i:%s') ";

            
    $war_sql .= ", @teamSize = '" $war["teamSize"];
            
    $war_sql .= "', @clan1_tag = '" $war["clan"]["tag"];
            
    $war_sql .= "', @clan1_name = '" mysqli_real_escape_string($conn$war["clan"]["name"]);
            
    $war_sql .= "', @clan1_level = '" $war["clan"]["clanLevel"];
            
    $war_sql .= "', @clan1_attacks = '" $war["clan"]["attacks"];
            
    $war_sql .= "', @clan1_stars = '" $war["clan"]["stars"];
            
    $war_sql .= "', @clan1_destructionPercentage = " $war["clan"]["destructionPercentage"];

            
    $war_sql .= ", @clan2_tag = '" $war["opponent"]["tag"];
            
    $war_sql .= "', @clan2_name = '" mysqli_real_escape_string($conn$war["opponent"]["name"]);
            
    $war_sql .= "', @clan2_level = '" $war["opponent"]["clanLevel"];
            if(isset(
    $war["opponent"]["attacks"]))
                {
                    
    $war_sql .= "', @clan2_attacks = " $war["opponent"]["attacks"];
                }
            else
                
    $war_sql .= "', @clan2_attacks = 0";

            
    $war_sql .= ", @clan2_stars = '" $war["opponent"]["stars"];
            
    $war_sql .= "', @clan2_destructionPercentage = " $war["opponent"]["destructionPercentage"] . ";\n";

        include 
    "../mysql_coc.php";

            
    $war_sql .= "INSERT INTO wars1 (`result`, `endTime`, `teamSize`, `clan1_tag`, `clan1_name`, `clan1_level`, `clan1_attacks`, `clan1_stars`,`clan1_destructionPercentage`, `clan2_tag`, `clan2_name`, `clan2_level`, `clan2_attacks`, `clan2_stars`, `clan2_destructionPercentage`) ";
            
    $war_sql .= "VALUES (@result, @endTime, @teamSize, @clan1_tag, @clan1_name, @clan1_level, @clan1_attacks, @clan1_stars, @clan1_destructionPercentage, @clan2_tag, @clan2_name, @clan2_level, @clan2_attacks, @clan2_stars, @clan2_destructionPercentage) ";
            
    $war_sql .= "ON DUPLICATE KEY UPDATE result=@result, clan1_stars=@clan1_stars, clan2_stars=@clan2_stars, clan1_destructionPercentage=@clan1_destructionPercentage, clan2_destructionPercentage=@clan2_destructionPercentage, clan1_attacks=@clan1_attacks;";

            
    $check_sql "SELECT count(*) from wars where endTime=STR_TO_DATE('" $endTime "', '%Y-%m-%d %H:%i:%s') AND (clan1_tag = '" $clantag "' OR clan2_tag = '"$clantag "')";

            
    $check_result mysqli_query($conn$check_sql);
            
    $check mysqli_fetch_row($check_result);
            if(
    $check[0]< 1)
                {
                    if (
    mysqli_multi_query($conn$war_sql) == TRUE) {
                        echo 
    "Record for \"" $war["clan"]["name"] . "\" vs. \"" $war["opponent"]["name"] . "\" updated successfully" "\n";
                    } else {
                        echo 
    "Error updating record for " $war["clan"]["name"] . ": " mysqli_error($conn) . "\n";
                    }
                    
                    while(
    mysqli_more_results($conn))
                        {
                            
    mysqli_next_result($conn);
                        }
                }
        }
    mysqli_close($conn);

    ?>
    I can see as output that the clanname1 vs clanname2 updated successfully ......

    for testing I changed the INSERT INTO wars1 for checking the database ..... the table wars1 does not real exist, so i got no error that the table not exist .....
    my thoughts are there is no db call ......

    Can anyone help me solve this problem ?
    my API projekt : my Clan Projekt

  2. #2
    With this partial code, impossible to answer. You should add some debug output, to understand what your code does exactly. Also, you should check return value for all mysqli calls. Especially, it would be interesting to echo the value of $check_result and $check, and the error messages, if any.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •