Database of users

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thedark_master
Forum Newbie
Posts: 8
Joined: Fri Feb 13, 2009 6:22 pm

Database of users

Post 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
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: Database of users

Post 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>
 
Post Reply