Sign in to follow this  
JamesCobras

Databases

Recommended Posts

JamesCobras    112
I'm trying to create a server (before you ask it's not an MMO server). I was going to go with a simple file per user system, but it really want to make it scalable and the file system search and read time would be way to much. Loading all data into RAM is out of the question (way to much data). After realising this and talking to a few mates i rediscovered sql (mysql?). I really don't know much about it, how efficient it is etc. What is the best way to do this (database or otherwise). Also where can i get a noob level and upwards tutorial. FYI I want to use the database in C++. Cheers JamesCobras

Share this post


Link to post
Share on other sites
implicit    504
Care to give us some more detail of what data you're storing and what you're doing with it? Without more information it's hard to give any useful advice.

Share this post


Link to post
Share on other sites
JamesCobras    112
Right, no problem.

Will be a bit like a social networking app. So profiles user data, non rapid access to data.

Just a technical exercise for me to help me under stand exactly how i would do it.

Basic user asks server searches for and pumps data to them, like friend profiles etc.

That more helpful?

JamesCobras

Share this post


Link to post
Share on other sites
DaveMS    187
Sounds perfect for a database in my opinion. I've only used databases with PHP and a few other server side laguages, but i'm sure you can find some way to get C++ interfacing with one.

Share this post


Link to post
Share on other sites
Atrix256    539
Yeah totally, sounds good.

databases are good for non time critical storage like what you are looking to do.

When you start looking at data for each player for each frame, the overhead of database operations becomes a really huge bottleneck.

But yeah, for your purposes, should be perfect (:

what database do you want to use? It looks like you are thinking mysql. Do you have that installed on your server? If so there are some good links when searching "c++ mysql tutorial".

Social networking apps of course are usually written in flash, not c++ since they don't have to download an exe (scary) and flash is multiplatform.

If I may make a recomendation, when talking to a database from C++, what i usually do is use libcurl to make HTTP requests to php scripts.

for instance, from c++ i tell libcurl to call up the url:
http://myserver.com/gameserver.php?function=getuserdata&userid=54

which returns something like below (where each field is on it's own line of data):
Johny Appleseed
Hi! I'm Johny, mess with me and you will be sorry!

I have libcurl write what was returned from that URL into a file, and then in my c++ code i open that file and read the data in.

This is typically how flash games communicate with game servers as well (and if wondering i shipped retail a wii, pc and ds game that used this technique to do content sharing between users)

Hope this helps!

Share this post


Link to post
Share on other sites
JamesCobras    112
This talking to server via php, getting it to produce a file and reading it in seems crazy.

There must be a more optimised way where you can get data straight into your app.

I'm surpised there were no, have a look at this lib.

most just seem to hack together CMD Prompt.

Is there any better way of doing this?

JamesCobras

Share this post


Link to post
Share on other sites
Atrix256    539
You can connect directly to your database from c++ yep.

The reason you wouldn't want to is security.

If your php talks to the database, you can define exactly what can and can't happen to your data because only the PHP generates and executes SQL.

If your c++ program connects to your database, once the connection is established from your program (which by the way HAS to store the database login information into itself!!!), people can send whatever SQL commands they want to your database.

They can modify any data however they want to, they can also just delete all your tables.

Going through php as the middleman is the secure way to do it and even then you have to be security minded in the PHP and set up a decent login system etc.

And sure, you can limit operations by having your sql login you use from inside the game be limited to only certain operations on certain tables, but still the security will be lacking.

HOWEVER

if you are making your server in c++, and it will be running on your server, throw all of this out the window and connect to the database directly.

What i'm talking about above is essentially doing the server logic in PHP.

Whatever you do, don't do the server logic client side :P

Share this post


Link to post
Share on other sites
JamesCobras    112
Yep server side only logic, yep i know the rules, trust no one but yourself (server).

Can anyone point me in the direction of a lib-database pair on the web that is commonly used.

Cheers

JamesCobras

Share this post


Link to post
Share on other sites
Mushu    1396
Quote:
Original post by Atrix256
You can connect directly to your database from c++ yep.

The reason you wouldn't want to is security.

You're assuming he's running the C++ code on the client. It's much more likely that he's looking to write some server software in C++ that interfaces with an RDBMS (e.g., MySQL) running on the same machine. In this case, proxying requests over a network is completely unnecessary and will introduce complexity and additional overhead.

Quote:
Original post by JamesCobras
Also where can i get a noob level and upwards tutorial.

FYI I want to use the database in C++.

If you're going to use MySQL (which is fine), I'd personally use the C bindings (only because they appear to be more officially maintained, and the C++ ones are probably just a wrapper around the C API anyway). Here is the documentation for the MySQL C API. If you google around, you can find tutorials of various qualities.

The other commonly used RDBMS is PostgreSQL which also has a C API that you can use.

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