Michael van Eck
Michael van Eck

Reputation: 1

Android MySQL + PHP + JSON

I've been working on this Android app with MySQL -> PHP and JSON for a school assignment. I'm NOT experienced with PHP and I can't find the error in this php file.

<?php

require("db_config.php");

//initial query
$query = "SELECT * FROM GAME G, CONSOLE C WHERE G.consoleid = C.consoleid";

//execute query
try 
{
    $stmt   = $db->prepare($query);
    $result = $stmt->execute($query);
}
catch (PDOException $ex) 
{
    $response["success"] = 0;
    $response["message"] = "Database Error!";
    die(json_encode($response));
}

$rows = $stmt->fetchAll();


if ($rows) 
{
    $response["success"] = 1;
    $response["message"] = "Games Available!";
    $response["games"]   = array();

foreach ($rows as $row) 
{
    $gameslist          = array();
    $games["gameid"]        = $row["gameid"];
    $games["gamename"]          = $row["gamename"];
    $games["gamevalue"]         = $row["gamevalue"];
    $games["gamerarity"]        = $row["gamerarity"];
    $games["gamedescription"]   = $row["gamedescription"];
    $games["consolename"]       = $row["consolename"];
    $games["gameimgstring"]     = $row["gameimgstring"];

    //update our repsonse JSON data
    array_push($response["games"], $gameslist);
}

    // echoing JSON response
    echo json_encode($response);   
} 
else 
{
    $response["success"] = 0;
    $response["message"] = "No games Available!";
    die(json_encode($response));
}

?>

The PHP script should return an Array filled with game data. It doesn't need any data for the Query.

My IDE gives an error on this part

try 
{
    $stmt   = $db->prepare($query);
    $result = $stmt->execute($query);
}

Because this fails it doesn't return a value.

Upvotes: 0

Views: 119

Answers (1)

Maxouille
Maxouille

Reputation: 2911

May be it is

$stmt->execute();

Check here : http://php.net/manual/en/pdostatement.execute.php

Upvotes: 1

Related Questions