【问题标题】:Android MySQL + PHP + JSON安卓 MySQL + PHP + JSON
【发布时间】:2015-04-03 12:00:20
【问题描述】:

我一直在使用 MySQL 开发这个 Android 应用程序 -> PHP 和 JSON 用于学校作业。我对 PHP 没有经验,我在这个 php 文件中找不到错误。

<?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));
}

?>

PHP 脚本应该返回一个包含游戏数据的数组。 Query 不需要任何数据。

我的 IDE 在这部分出现错误

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

由于失败,它不会返回值。

【问题讨论】:

  • 你不需要把sql语句放在-&gt;execute()里面

标签: java php android mysql json


【解决方案1】:

可能是这样的

$stmt->execute();

在这里查看:http://php.net/manual/en/pdostatement.execute.php

【讨论】:

    猜你喜欢
    • 2015-09-06
    • 2013-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    • 1970-01-01
    • 2011-05-17
    相关资源
    最近更新 更多