4 Replies - 984 Views - Last Post: 25 May 2010 - 12:50 AM

#1 GreenSpiral  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 64
  • Joined: 30-December 08

Help with databases in as3

Posted 20 May 2010 - 05:44 PM

I am making a game in which I want the my game to be able to connect to a database and add a piece of text to the database (around 100 - 500 characters in lenght). The game must also be able to retrieve any piece of text from that database (around 50 - 150 different texts). The text is a level by the way. Each text also needs to have a some information such as name, picture, date, rating, etc. I would also like to be able to group the levels into level collections. I must be able to edit the database too.

I've been reading about flash and databases. So I know I need to host this database and have asp or php or something else. I am a little confused right now though.

What kind of code do I need in my game?
How do I make a MySQL database?
Can I use a free hosting website?
What about security?
How can I stop hackers from editing my database?
How do I stop people from spamming my database with junk?
What other security problems might I face?


I'm not asking for anyone to do this for me, I just need to be pointed in the right direction of where I can find this information and some answers to my questions.

Thanks to anyone who can help.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with databases in as3

#2 depricated  Icon User is offline

  • RISC Architecture is going to change everything.

Reputation: 929
  • View blog
  • Posts: 3,009
  • Joined: 13-September 08

Re: Help with databases in as3

Posted 20 May 2010 - 08:13 PM

Very good questions. Let me offer the best answers I can.

First off, you're right in that you'll need PHP. Many free hosts offer PHP. However, I'm not aware of any which off MySQL Databases. That said, there are a number of hosts who offer MySQL and PHP. I personally use GoDaddy. At any rate, feel free to look around and see what you can find.

So to answer your question, "how do I make a MySQL Database" let me ask you - do you know SQL? MySQL is very similar to SQL, obviously. There are small differences here and there, but for the most part the Syntax works the same. If you don't, I'd recommend reading up on using SQL. Hosts which provide a MySQL Server will typically have something like PHPMyAdmin installed to allow you administer the database directly. You can also do it by querying with PHP.

I recently taught a class on PHP, and below I'll paste a few points from my lesson plan and I'll attach the handout I used. That should help you with PHP and understanding how to interact securely with the database.

But the important intermediary step is actually XML. What you'll need to do is save your information into an XML File, and then use PHP to pass the information over to the Database. You'll also need to reverse the process in order to query the database from the game. This isn't a light undertaking, but there is a lot of information available on the subject.

Here's a link that further explores this method. http://library.creat...e/php_mysql.php

Stopping people from spamming your database with junk is a bit challenging. My own database is, I feel, rather secure, but I still get spammed by bots now and then. Fortunately, with the security in place, the junk gets ignored hangs in stasis. It does no damage, which there is potential to.

One form of attack is called an injection, wherein code is sent to the database. It terminates line and then does something like drops the Users table. Something like this, http://xkcd.com/327/ .

Since you'll be using PHP to manipulate the raw data, though, there are a few easy steps you can take in preventing this. First you can validate the data you receive to be sure that it's appropriate. Make sure your numbers are numbers, etc. Second you can use mysql_real_escape_string, a built-in PHP function which puts an escape slash in front of anything that might end the string(so that it remains a string in the query and doesn't run as a command, instead).

There's also the mysql_connect and mysql_close functions. You can create a dbopen and dbclose script that does this, imo it's faster and easier, though some people don't bother. Another important thing though is to make sure your database settings - login, password, address, etc - is in a script that sets them as variables, and CHMOD that to 400 so that only scripts on the server can access it(and therefore those variables).

This is convoluted, I know, but I hope it helps. The last bits for PHP you'll want are mysql_query, which lets you construct a String and returns a dataset. So you might do something like $data = mysql_query("SELECT * FROM level WHERE levelID = '3'"); to run your query. Then you would need to use mysql_fetch_array in order to get the data from the row. Actually, you know what? I'll attach my PowerPoint also, it goes over all of this in a lot better detail.

Warning though, it's a little tongue in cheek at times. I was close with the class I taught so wrote this to have a little humor, and we tease each other.

Hope they help.

Unfortunately, though your questions are relative to Flash, and specifically using Databases with Flash, the answers may push this to the PHP forum.

Attached File  PHP for Morans.ppt (165K)
Number of downloads: 661
Attached File  Handout.doc (53.5K)
Number of downloads: 138
Was This Post Helpful? 0
  • +
  • -

#3 Guest_GreenSpiral*


Reputation:

Re: Help with databases in as3

Posted 21 May 2010 - 01:04 PM

Wow! Thanks alot. I'll read through the stuff when I have the time.
Was This Post Helpful? 0

#4 GreenSpiral  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 64
  • Joined: 30-December 08

Re: Help with databases in as3

Posted 21 May 2010 - 05:39 PM

I'm wondering what do I use to send my variables to php and how do I receive them in php?
Was This Post Helpful? 0
  • +
  • -

#5 depricated  Icon User is offline

  • RISC Architecture is going to change everything.

Reputation: 929
  • View blog
  • Posts: 3,009
  • Joined: 13-September 08

Re: Help with databases in as3

Posted 25 May 2010 - 12:50 AM

View PostGreenSpiral, on 21 May 2010 - 04:39 PM, said:

I'm wondering what do I use to send my variables to php and how do I receive them in php?

I'm still learning AS3 myself and haven't messed around with this too much yet. One of the links I posted above should detail how to pass the information back and forth between a Flash application, XML, and PHP.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1