Levent Tulun
Levent Tulun

Reputation: 711

Request Http Url

I just want to call script.php to control the database like a polling.

Here is my code,

but it gives error : can not resolve HttpClient.

HttpClient httpclient = new DefaultHttpClient();
httpclient.execute(new HttpGet("http://www.holobech.com/script.php"));  

also here my script.php which is check the time and create a table every day :

<?php
require "includes/database.php";
require "classes/C_UserList.php";
require "classes/C_GlobalClass.php";

$current_game = GlobalClass::fetchinfo("value", "info", "name", "current_game");

$today = date("Y-m-d H:i:s");
$objUserList = new UserList;
$game_started_at = $objUserList->getTotalTime($current_game);

$diff = abs(strtotime($game_started_at . "+1 days") - strtotime($today)); 
$one_day = 60*60*24;
if ($diff >= $one_day) {
    $db_connect = Database::connect();
    $old_game = GlobalClass::fetchinfo("value", "info", "name", "current_game");
    $new_game = $old_game + 1;
    $sql = "UPDATE info SET value = ? WHERE name = ?";
    $query = $db_connect->prepare($sql);
    $query->execute(array($new_game, "current_game"));

    $sql = "CREATE TABLE game".$new_game."(
                id INT AUTO_INCREMENT PRIMARY KEY,
                uid INT NOT NULL,
                highlighting INT NOT NULL,
                sent_who INT NOT NULL,
                sent_amount VARCHAR(255) NOT NULL,
                sent_at DATETIME DEFAULT NULL,
                joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )";
    $query = $db_connect->prepare($sql);
    $query->execute();

    $sql = "SELECT * FROM game".$old_game;
    $query = $db_connect->query($sql, PDO::FETCH_ASSOC);
    if ($query->rowCount() > 0) {
        $rows = $query->fetchAll();
        if (count($rows) == 1) {
            $sql = "INSERT INTO game".$new_game." SET uid = ?, highlighting = ?";
            $query = $db_connect->prepare($sql);
            $query->execute(array($rows[0]["uid"], $rows[0]["highlighting"]));
            $game_card = 1;
            $highlight_card = $rows[0]["highlighting"];
        } else {
            for ($i = 0; $i < count($rows); $i++) {
                $sql = "SELECT played FROM user_game_info WHERE uid = ?";
                $query = $db_connect->prepare($sql);
                $query->execute(array($rows[$i]["uid"]));
                $played = $query->fetch();
                $sql = "UPDATE user_game_info SET at_game = ?, game_card = ?, played = ? WHERE uid = ?";
                $query = $db_connect->prepare($sql);
                $query->execute(array("0", "0", $played["played"], $rows[$i]["uid"]));      
            }
            $game_card = 0;
            $highlight_card = 0;
        }
    } else {
        $game_card = 0;
        $highlight_card = 0;
    }

    $sql = "INSERT INTO games SET game_id = ?, money_amount = ?, game_card = ?, highlight_card = ?, started_at = NOW()";
    $query = $db_connect->prepare($sql);
    $query->execute(array($new_game, "0", $game_card, $highlight_card));
}
?>

Upvotes: 0

Views: 80

Answers (1)

Anup Dasari
Anup Dasari

Reputation: 488

Apache Http is deprecated. Add

  useLibrary 'org.apache.http.legacy'

in app's build.gradle file in defaultConfig to use apache httpclient.

Upvotes: 2

Related Questions