- Home /
Best way (performance) to connect to a (MYSQL) DB
So we making a network based game (Dungeon Crawler). The architecture of the network code will be authoritative server based. All the communication to the DB will be done by the Server.
All informations about player and items should be stored in a DB (MYSQL). What is the best way to do this? (Cant find any good tutorial). How to connect to DB ? I read about 2 ways:
With PHP (bad Performance ?)
With a MYSQL connector (DLL files to install) -> Dont sound like this will work on Linux later on...
So how this works ?
Hope someone can help me with this.
Thx & Greetings
Teiwaz
Answer by clunk47 · Aug 29, 2013 at 08:17 PM
This is for serverside high scores, but it shows you how to add info to a db, as well as receive information. It also shows you how to use md5 for security, so people can't just type the values they want to add in their address bar, and potential cheat. Overall it's a good tutorial on how to have your UnityScript or C# Script communicate with your php script located on your server, whether it be local or web, and send and receive information to and from your sql db tables.
http://wiki.unity3d.com/index.php?title=Server_Side_Highscores
Thanks i saw this before. But i was wondering if this has good performance. I mean c´mon. you have to call php for any action you want to store in the DB. Is there no other way ?
It's a matter of design. Why would you want your players to connect to the DB directly? Assu$$anonymous$$g that you do not need to use the DB that often (just to adjust some values which might happen every couple seconds) It's probably always better to have an API in place that takes care of the communication between the client and the server/DB ins$$anonymous$$d of having your players connect directly to the DB.
For starts, it would probably mean storing your DB access info in your code or somewhere else on the clients side, which would mean that they'd be able to find it out in some way.. which you obviously don't want to happen.
Now if they call a simple link you have all control over what happens on the server and the DB. The DB isn't exposed to the player directly and you'r able to check the data that your server receives to make sure that somebody isn't cheating.
You just have to make sure that the sever checks the inco$$anonymous$$g data before forwarding it to the DB or else everyone could do exactly what clunk47 said.. specify some values for the URL and just send them directly to your DB.
[edit] Unless you meant with "server" another client in which case you can probably ignore all this since it would be just a local DB.
@ShadoX: The question points out authoritative server based. So, the clients connect to the remote headless server, and the server can make a direct secure localhost connection to a mysql database. 3306 can be blocked by the firewall so there is no remote mysql access. Credentials could be stored on the server outside of the build binary so clients don't even have credentials if the mysql server wasn't firewalled. The php method is okay if clients are sending messages, but even the hash can be reverse engineered. It just raises the barrier a bit.
Edit: Sorry I didn't look at date stamps, this was a top result on google when searching for unity and mysql.
Answer by Hybrid1969 · Oct 02, 2014 at 11:39 AM
I currently use the DLL method which works extremely well but it really comes down to how many INSERT/UPDATES you intend throw at MYSQL and if those responses are time critical.
The majority of the queries i currently do are saving user and game data every X seconds and retrieving game data and AI influence updates made by our AI & Event servers every X seconds and so far its not been an issue.
I am currently contemplating a Threaded async queue system for MYSQL queries to see if I can improve server load and data throughput..
Your answer
Follow this Question
Related Questions
Web Player and database 1 Answer
Is it possible to send and recieve data from/to a MySql server? 4 Answers
Performance Question MySQL 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to use php to update mySQL 1 Answer