使用 php unity3d 从数据库中检索单个值


Retrieving a single value from database using php unity3d

我正在制作类似的RPG游戏,用户可以在其中登录并保存和加载数据。我可以登录并保存。但是,当我想加载数据时,加载它时遇到了麻烦。

我将只发布必要的代码(PHP代码(加载.php)):

<?PHP
$Username = $_POST['Username'];
$Location = $_POST['Location'];
$Gold = $_POST['Gold'];
$Level = $_POST['Level'];
$Attack = $_POST['Attack'];
$Defense = $_POST['Defense'];
$MagicDefense = $_POST['MagicDefense'];
$Evasion = $_POST['Evasion'];
$Health = $_POST['Health'];
$MaxHealth = $_POST['MaxHealth'];
$Mana = $_POST['Mana'];
$MaxMana = $_POST['MaxMana'];
$Exp = $_POST['Exp'];
$NextExp = $_POST['NextExp'];
$AcceptedChiefQuest = $_POST['AcceptedChiefQuest'];
$AddedChiefQuest = $_POST['AddedChiefQuest'];
$con = mysql_connect("SERVER_NAME","DATABASE_NAME","PASSWORD") or ("Cannot connect!"  . mysql_error());
if (!$con)
    die('Could not connect: ' . mysql_error());
mysql_select_db("DATABASE_NAME" , $con) or die ("Could not load the database" . mysql_error());
$check = mysql_query("SELECT * FROM Information WHERE `Username` = '".$Username."'");
$numrows = mysql_num_rows($check);
if ($numrows > 0)
{
    while($row = mysql_fetch_assoc($check))
    {
        $Username = $row['Username'];
        $Location = $row['Location'];
        $Gold = $row['Gold'];
        $Level = $row['Level'];
        $Attack = $row['Attack'];
        $Defense = $row['Defense'];
        $MagicDefense = $row['MagicDefense'];
        $Evasion = $row['Evasion'];
        $Health = $row['Health'];
        $MaxHealth = $row['MaxHealth'];
        $Mana = $row['Mana'];
        $MaxMana = $row['MaxMana'];
        $Exp = $row['Exp'];
        $NextExp = $row['NextExp'];
        $AcceptedChiefQuest = $row['AcceptedChiefQuest'];
        $AddedChiefQuest = $row['AddedChiefQuest'];
        echo $Location;
    }
        die("Successfully Loaded!");
}
else
{
    die ("Data does not exist!");
}

?>

在这里,我通过 Unity 中的脚本访问它(问题所在的必要代码):

IEnumerator LoadCoroutine(WWW _www)
    {
        yield return _www;
        if (_www.error == null)
        {
            message = _www.text;
            if (_www.text == "Successfully Loaded!")
            {
                // Below code from this line, never gets executed (if and else if statement)
                // The `GameManager.CurrentLocation` appear as default value
                if (_www.text == "Village")
                {
                    GameManager.CurrentLocation = "Village";
                    GameManager.Loader = 1;
                }
                else if (_www.text == "Yein Plain")
                {
                    GameManager.CurrentLocation = "Yein Plain";
                    GameManager.Loader = 4;
                }
                // Below code from this line will gets executed.
                message = "Successfully Loaded.";
                mainMenu = false;
                yield return new WaitForSeconds(3);
                Reset();
                GameManager.LoadLevel("Loading Scene");
            }
            else if (_www.text == "Data does not exist!")
            {
                message = "Data does not exist";
                clickedLoadGame = false;
            }
            else if (_www.text == "Saved data does not match!")
            {
                message = "Saved data does not match";
                clickedLoadGame = false;
            }
        }
        else
        {
            message = "Error while trying to connect to the server.'nMessage: " + _www.error;
            clickedLoadGame = false;
        }
    }

当我Debug.Log message时,它看起来像这样:VillageSuccessfullyLoaded!,它从来没有像这样出现VillageYein Plain。似乎 PHP 代码中的echodie组合在一起。

我的问题是,如何仅从 php 中检索$Location而不是其他代码?所以它只会返回VillageYein Plain.

非常感谢您的回答!

谢谢

更改

die("Successfully Loaded!");

die();

然后:

        if (_www.text == "Data does not exist!")
        {
            message = "Data does not exist";
            clickedLoadGame = false;
        }
        else if (_www.text == "Saved data does not match!")
        {
            message = "Saved data does not match";
            clickedLoadGame = false;
        }
        else
        {
            if (_www.text == "Village")
            {
                GameManager.CurrentLocation = "Village";
                GameManager.Loader = 1;
            }
            else if (_www.text == "Yein Plain")
            {
                GameManager.CurrentLocation = "Yein Plain";
                GameManager.Loader = 4;
            }
            message = "Successfully Loaded.";
            mainMenu = false;
            yield return new WaitForSeconds(3);
            Reset();
            GameManager.LoadLevel("Loading Scene");
        }