Page 1 of 1

Database of users

Posted: Tue Nov 24, 2009 10:28 am
by thedark_master
Hello,

I am a flash developer that will be creating a flash game. I need the users to be able to save and load their place in the game. This information I want to be stored in a database in my server. The only thing I know how to do is send the variables from the Flash game to PHP. From this point I have no idea how to code the PHP to communicate with a database. I am completely new to this. So I want to create a database which will communicate through PHP with the Flash game. It will store a username, password, and variables for each username.

Thank you for your help

Re: Database of users

Posted: Tue Nov 24, 2009 11:33 am
by Grizzzzzzzzzz
The way that i've communicated between Flex(pratically the same thing) and databases is via xml outputted by the php.

i.e:

Flash sends off an HTTPService, the HTTPService is directed to a php file which accesses a database(there are more than enough tutorials lying around to get you started there). And a Result event handler accepts the returned xml that the php printed, for eg:

Code: Select all

 
<?php
 
mysql_connect('databasehost', 'username', 'password');
    mysql_select_db("PlayerDatabase");
 
$query="SELECT * FROM players";
$result=mysql_query($query);
$rows = mysql_num_rows($result);
 
$i = 0
 
while ($i < $rows)
    {
        $Name = mysql_result($result, $i ,"playername");
                $Password = mysql_result($result, $i ,"password");
        
                print "<player><playername>".$Name."</playername><password>".$Password."</password></player>";
        $i++;
    }
?>
 
will give you all the usernames and passwords in the database.

You can use the same principle for logging in; a player enters their username + password, the php connects to the database and sees if there is a match, if there is then output something like

Code: Select all

 
<success>Yes</success>
 
if not

Code: Select all

 
<success>No</success>