0

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.

1
  • you do not need to put the sql statement inside ->execute() Commented Apr 3, 2015 at 12:02

1 Answer 1

1

May be it is

$stmt->execute();

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.