Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Teiwaz · Aug 29, 2013 at 08:12 PM · performanceconnectionmysqlphp

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Teiwaz · Aug 30, 2013 at 07:36 AM 1
Share

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 ?

avatar image ShadoX · Aug 30, 2013 at 11:29 AM 3
Share

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.

avatar image sarynth · Mar 25, 2018 at 05:12 PM 0
Share

@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.

avatar image
1

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..

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges