Sign in to follow this  
julian boolean

databases

Recommended Posts

hey all could anyone elaborate a little on databases for games and how i could create/use one. im using c++ (to which im still a newbie at) and have extremely limited knowledge on them.. mysql? lol thanks ;)

Share this post


Link to post
Share on other sites
Firstly, you need to think about why you actually want one.

For example you may just want a database to hold a list of highscores for a pong clone through to a database holding all kinds of info on stats/inventory/character detail etc etc etc for an RPG.

Once you've figured out what information you want to hold, you've then got to figure out how you want to group the information.

A highscore database could just hold one table with a list of highscores. At the end of each game, you'd run some code to check the player's score against the scores held in the table and insert as appropriate.

For an RPG it'd be ALOT more complicated. For instance, you could have a table with information on weapons, holding a weapon's type, its hit strength, any special features etc.

Depending on how many different weapons you have though it could be a better idea to separate out the tables i.e.

a table that holds the names of all the different weapon types

for each weapon type there could be a table that holds its name and some stats about it

on the other hand, the weapon name table may just hold the weapon name, with a further table linked in to hold the weapon's stats

It really does come down to what type of game you want to make, what type of information you want to hold and you will have to make some choices on how to structure the storage.

For any sort of large scale use, like the RPG example, you will need to read up on using table keys and normalisation, they will give you an idea of when/why you should hold the data in different tables instead of in one giant one.

As for creating and using one, there are better people than me here to suggest what to use, I use SQL Server simply because that's what my employer uses, there could be free stuff out there.

http://www.w3schools.com/sql/default.asp

has a nice guide to working with SQL.

That's about all I can think of, apologies if I'm unclear in anything I've said but just post back if there's anything you'd like me to clear up.

Share this post


Link to post
Share on other sites
You need to decide if you really need a database. If you are just storing static information or high scores then you really don't need a database. Databases are best when the data is changing a lot.

If you just need to store game information, such as RPG quests information, world information, ect. then there are many other ways of doing it.

If you do decide that you need a database then you really need to look into database design and database normilization. The design of the database is a huge part of the project. A badly designed database will make your programming a lot hard and also be a huge proformance hit.

theTroll

Share this post


Link to post
Share on other sites
Also, it's not usually feasable to write a non-online game that needs a database. You can't usually deploy a database on a client machine, (With the exception of SQLite which just runs in a DLL) since most databases run as Windows services.

If you're running a database, you usually want the database and application running on a server machine, and have the clients connect to the application to request information from the DB. Allowing client applications to connect directly to the DB is just asking for trouble.

Share this post


Link to post
Share on other sites
Quote:
Original post by 3dnewbie
Quote:
Allowing client applications to connect directly to the DB is just asking for trouble.


Why?


one reason I see is that you have a direct link to the database from the client application, now if you connect to an app - which will filter any crap coming in, this seems to be taking better precautions for security reasons.

Share this post


Link to post
Share on other sites
You don't want your clinets to directly access the database for secruity and performace issues. First you want to make sure they are not changing things they should not be. You should always assume the client is not secure, so you need verify everything that is sent by the client. So if you had a database that stored the player's money, the client could be hacked and the person could give themselves as much money as they wanted to. Next, you do not want hundreds or thousands of connects to the database becuase it degrades performance.

theTroll

Share this post


Link to post
Share on other sites
Connecting to a database is resource intensive, plus I think there's a limit to the amount of open connections you can have at a certain time, so it's best to let the client connect to an app that manages all this instead. Plus adding a layer of abstraction to connecting to the database helps with security.

Or so my head leads me to believe anyway

Share this post


Link to post
Share on other sites
Sorry if i rub people the wrong way now, but these are all b*s reasons as far as i can see.

1. The database and server it is running on should _already_ be secure. Having middleware as an arbiter in the middle filtering out 'bad' stuff is just making things more bloated and obscure, not to mention you add an extra bottleneck to the infrastructure.

Not for security and performance reasons, i think that should be thus the other way around. You _want_ them to access the db server directly, _because_ of those very reasons.

You can put all those limitations (connection throtteling, security etc.) on the server and in the db itself. If you really dont trust the sql security itself, sure you can add some filter in between but i don't i would do it. Instead, first time the sql servers get hacked, -> more work for the sql team to fix something.

Share this post


Link to post
Share on other sites
3dnewbie, you are missing a few things here. Well a lot of things. First of all there are two types of security we are talking about here. One is the secruity of the database. Yes that can somewhat secured using other methods. The other is data securtiy. Who do we make sure that the data being sent from the client is valid? Well you can't do that unless there is something between the client and the database to make sure people are not cheating.

Next each database connection is very very resource intensive. The goal is to use as few as you can to keep things moving along nicely. The more connections you add the move the db has to deal with locking issues and with polling issues. These slow the db down.

theTroll

Share this post


Link to post
Share on other sites
3dnewbie:

1) You can't afford (for a single game) a server and supporting hardware/bandwidth/software that can handle the amount of data traffic you will experience with direct connections.

2) You will not be able to provide a fast enough response to your client base with direct connections - queries take time.

3) You cannot create a secure enough environment to allow direct connections.

4) If you are considering a "pay" product, you can't afford the legal representation you will need when all your customer data is stolen, corrupted, abused, etc.

[Edited by - DirtyBill on November 8, 2006 9:26:45 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this