.:: Alex Erne :: PHP/MySQL & Unity3D/C# projects ::.
Recent news
Categories
Like me on Facebook
* advertisement *
  23 May 2016 - Unity, Linux & MySQL (or the start of a persistent online world) :: Posted in Unity3D

Today I've been experimenting with the MySQL .DLL files, which can be used to allow the Unity engine to connect to a database. Of course, it's not recommended to let a client game connect to a database because of security issues. On the server side of things though it's not a problem, where the clients connect to the server side program, which in turn connects to the MySQL database and submits the results back to the client. This way there's no security risk at all, and (more importantly) will allow to creation of a persistant online world (either small scale multi-player game or even a MMORPG).

I've been thinking about making a persistant online world for a bit longer than the last couple of days (also see yesterday's blogpost). The bookmarks I've made on the use of (remove) MySQL servers are from the time I started working on TetraGems, back in 2013 already. But I never really did something with them because I had no use for a persisntant online world at the time. But ever since I've started on the d20 project, the thought about creating a persistant online world grew stronger and stronger. And with last week's first tests on client-server connections, the next logical step was to see how Unity works with MySQL...

One of the most important plugins for MySQL to use with Unity is not in the asset store, but discussed on the Unity forums. In fact, it's quite an old thread as well! Dispite this thread being so old and the .DLL files that come in the package are as old too, they still DO work with the latest versions of the MySQL databases. The only thing that bugged me of that plugin and documentation was that massive load of useless data it has. Okay, it's an example project where player data is stored, but that's not directly what I wanted to test. I wanted to see HOW it all worked with as few lines as possible. And being a certified PHP/MySQL programmer, it couldn't be that hard to get a simple piece of code going...

 photo Unity MySQL reading_zpst9v6omlk.png

And indeed it's not that hard to get MySQL going with Unity under Windows. I fired up my Wamp Server where I still have the old test database of the I am Blog project (BTW that project is dead now that I'm into Unity ) and I gave it a couple of tries with queries I took from the I am Blog code. First the simple ones and they worked flawlessly. Then a couple with nested queries and those worked very well too! Basically everything I've learned from the PHP/MySQL certification can be used in Unity as well. There is one problem though. Where in PHP you can easily process the code, in Unity distilling the data is less programmer friendly (at first glance I must add - I still have to dive deeper into it) and every query needs it's own.
...while reading this I think I could use a return(myReader) for the MySQLRead() method and process the data somewhere else, allowing me one reading method and different processing methods...

Under Windows it's all working, but what do you expect with .DLL files that originate from the platform..? How about using these .DLL files under the Linux version of Unity..? I copied the project to my Linux machine (which will become the server of my persistant online world) and the Unity editor accepted the code and .DLL files without a problem. The only problem though is(was) the lack of a MySQL server on the Linux machine.
With Wamp server being a Windows Apache/PHP/MySQL server, I was in need of something similar for Linux. I did find a couple of similar packages, but all required me to logon as root on Linux. And being still very much a newbee on Linux I had no clue how to solve that.

When I looked in the Ubuntu Program Manager I found a MySQL working space that'll visualize your databases, which is exactly what I need. I don't need some Apache server package when I only need a MySQL database installed. Of course, the MySQL database server itself is available for Linux as well, and installing those 2 solved my problems. After having meddled with theMySQL working space program and figuring out how everything works, I could import the test database and run the same code under Linux. Aside from a couple of import errors (somehow MySQL imports tables always in LOWERCASE) and chancges to my C# code, the output was the same as I had under Windows.

Now with both being able to use client-server connections AND work with MySQL under Unity, the next challenge comes: figure out what the best coding configuration for the server will be and how stuff is handled there for the clients. I don't want the client to have any checks of the game, but instead it has to get the data from the server...

[NOTE] I will make a full guide/documentation on how to implement MySQL with Unity later on this year (when I've figured out all the things to know of the DLLs included)


Post A Comment!
Your comment:
Title

Your name

Image text
* advertisement *
* advertisement *

This website is Copyright © 2009 - 2016 Alex Erné
PHP/MySQL coding by Alex Erné Copyright © 2009 - 2016 Alex Erné
...all rights reserved...

AE games™ and the AE games logo are Trademarks owned by Alex Erné
TetraGems™, Burst-a-Bubble™ and the Burst-a-Bubble logo are Trademarks owned by Alex Erné