Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法从flash游戏中动态访问mySQL数据库的更新版本_Php_Mysql_Flash_Actionscript 3 - Fatal编程技术网

Php 无法从flash游戏中动态访问mySQL数据库的更新版本

Php 无法从flash游戏中动态访问mySQL数据库的更新版本,php,mysql,flash,actionscript-3,Php,Mysql,Flash,Actionscript 3,我用ActionScript3创建了一个游戏。在这个游戏中,我将分数保存到在线mySQL数据库中。我通过调用使用URLLoader类编写的php脚本,从flash游戏中访问该数据库 我加载所有玩家的分数,以便在游戏开始时查看它们,然后保存为完成关卡 我的问题是,一旦我保存了一个分数,然后在主菜单上重新加载所有分数,我就会检索游戏开始时加载的分数,而没有更新的分数。我只有在重新开始游戏时才能查看更新的分数 下面是加载我的分数的actionscript代码。当主菜单初始化时,会调用一次 getSco

我用ActionScript3创建了一个游戏。在这个游戏中,我将分数保存到在线mySQL数据库中。我通过调用使用URLLoader类编写的php脚本,从flash游戏中访问该数据库

我加载所有玩家的分数,以便在游戏开始时查看它们,然后保存为完成关卡

我的问题是,一旦我保存了一个分数,然后在主菜单上重新加载所有分数,我就会检索游戏开始时加载的分数,而没有更新的分数。我只有在重新开始游戏时才能查看更新的分数

下面是加载我的分数的actionscript代码。当主菜单初始化时,会调用一次

getScoresRequest = new URLRequest("http://localhost/GetScores.php");
getScoresRequest.method = URLRequestMethod.GET;
getScoresLoader = new URLLoader();
getScoresVariables = new URLVariables();

getScoresVariables.email = Globals.email;
getScoresRequest.data = getScoresVariables;

getScoresLoader.dataFormat = URLLoaderDataFormat.TEXT;
getScoresLoader.addEventListener(Event.COMPLETE, completeHandler);
getScoresLoader.load(getScoresRequest);

private function completeHandler(e:Event):void
{
    var xmlData:XML = new XML(e.target.data);
}
然后我使用这个xmlData来显示我的分数

以下是我的php,用于加载我的分数:

<?php

$email = $_REQUEST["email"];

$dbh=mysql_connect ("**********", "*****", "*******")
or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("*******",$dbh);

$query = "SELECT * FROM Scores WHERE email = '$email'";

$result = mysql_query($query, $dbh);

$xml_output = "<Scores>\n";

for($x = 0; $x < mysql_num_rows($result); $x++)
{
    $row = mysql_fetch_assoc($result);
    $xml_output .= "\t<Entry>\n";
    $xml_output .= "\t\t<Level>" . $row['level'] . "</Level>\n";
    $xml_output .= "\t\t<Score>" . $row['score'] . "</Score>\n";
    $xml_output .= "\t</Entry>\n";
}
$xml_output .= "</Scores>";

echo $xml_output;


mysql_close($dbh);

?>

我保存分数的actionscript非常类似于使用loader的exeption加载。dataFormat设置为变量而不是文本。如果有人想让我发布这个,我可以

以下是用于保存的php:

<?php
$email = $_REQUEST["email"];
$level = $_REQUEST["level"];
$score = $_REQUEST["score"];

$dbh=mysql_connect ("******", "********", "********")
or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("********",$dbh);

$query = "SELECT * FROM Scores WHERE email = '$email' AND level = '$level'";

$result = mysql_query($query, $dbh);
$row = mysql_num_rows($result);

$returnVars = array();

if($row > 0)
{
for($x = 0; $x < 1; $x++)
{
    $currentRow = mysql_fetch_assoc($result);

    if((int)$score > (int)$currentRow['score'])
    {
        $returnVars['prevHighScore'] = $currentRow['score'];
        $updateQuery = "UPDATE Scores SET score = '$score' WHERE email = '$email' AND level = '$level'";
        $result = mysql_query($updateQuery, $dbh);
        $returnVars['newHighScore'] = $score;
        $returnVars['type'] = "Score Updated";
    }
    else
    {
        $returnVars['prevHighScore'] = $currentRow['score'];
        $returnVars['newHighScore'] = '0';
        $returnVars['type'] = "Score Not Updated";
    }
}
}
else
{
    $insertQuery = "INSERT INTO Scores(email, level, score) VALUES('$email', '$level', $score)";
    $result = mysql_query($insertQuery, $dbh);
    $returnVars['newHighScore'] = $score;
    $returnVars['prevHighScore'] = "0";
}
$returnVars['rows'] = $row;
$returnString = http_build_query($returnVars);
echo $returnString ;

mysql_close($dbh);

?>
厚颜无耻地添加我自己的评论作为答案


尝试向url添加随机值。比如:

http://localhost/GetScores.php?_rand=0.12324343213

并在每次访问源时重新生成此值。

尝试向url添加随机值。比如:
http://localhost/GetScores.php?_rand=0.12324343213
并在每次访问源代码时重新生成此值。我是否必须执行其他操作才能使此值正常工作,就像我将其添加到url时遇到意外变量错误一样。我尝试将变量添加到php文件中,但仍然不起作用。我猜在您的通信中,
http://localhost/GetScores.php
get被缓存。因此,添加一些东西使请求唯一(随机值)通常是最好的方法。我对flash了解不多,但也许会对你有所帮助?不幸的是,CacheResponse仅在空中运行时可用。然而,我得到了你的随机数的想法工作,它修复了我的问题。谢谢:)您真的不应该使用for循环进行mysql查询。