Sql Lite : How to start up database for my games

Hi all, basically i have been searching around the forum on how to set up database for my game. But i still find it confusing and am kinda stucked on how to start setting up the database. I would appreciate if someone could help me out to get started with it.

From what i read up, sql Lite seem to be more suitable for my games. Need advice on it.

Thank you.

When we talk database’s, we talk of how to get information stored and restored quickly and efficiently. When we talk installing a database on a person’s machine, we talk lots more than that.

The first question is, what are you designing and why?

Lets say you wanted an MMO style game and you wanted millions of people to access the same game. Well, installing a database on a local user’s machine wouldn’t work at all since you want others to share in the experience.

Installing it on an RPG, where no one else shares? This is still impractical as you probably wont need that much storage for a game.

installing it on a Web server? There should already be a MySQL server installed there.

The only one that would bear interest and explaining would be a local game. 99.9% of the time, if you need to store information for a local game, you would do so in the form of files. (XML, text, CSV or whatever you want to read)

I don’t know if this answers your questions or raises more.

Hello BigMisterB,

Basically i am creating an single/multi-players educational game.

This is where i need database.
For example, player click on the word “A T E” and this is the correct word formation “ATE”. So i need a database to check if the word formation are valid. Beside that, i would like to add in explanation to the word form. Like “A T E” mean that “the past tense of eat etc”. I have been looking around and i find it very confusing and stucked that i don’t know how to get started. I have already download sqlLite. Now what i need it to set up the database inside Unity and start using it.

I would appreciate if you could guide me.

IC, you should not be looking at a database at all in this case. You are looking for a text file containing all of your data.

consider the following lines:

ate:The past tense of eat
deer:A woodland animal with antlers and hooves
apple:A round red or yellow fruit from a tree

So with our text file of thousands of words and explanations we can get a similar asset to a database, but without the overhead of connecting, getting and parsing the information.

Is this more what you have in mind?

I have thought of using a text file or xml to store all my words. But databases issnt a better choice? Because i personally feel that since i am creating an educational games, with database include in the game will increase the flexibility of the information. What i mean is that rather den using it for english games, i could change it to chinese, mathematics games.

In terms, a text or xml file is a database. The pure point of using SQL in the first point is not to retrieve data, but also to store it. Does your game store and retrieve data where making a slower text based file would not suffice, or are you just reading information and throwing on a screen?

I am considering to monitor the progress of the player. Like how the player score and what kind of mistake( for example, what if this game integrated into mathematics,science)? This database basically for the teacher to monitor the progress of the student and store the explanation of the words and display it to the player.

bump

I would advise you to try first with mySQL, since as BigMisterB says is common to every webserver and there are tons of tools to administer that database. Try a LAMP solution (LINUX+APACHE+MYSQL+PHP) because is easier to install than a mysql server.
As for communicate with the database i think is done via scripts on webserver (php if you go with lamp). By default mysql does not allow connections from outside world, is only listening to localhost or 127.0.0.1. The WWW class in unity will help you here.

Hello scarpelius, i would appreciate if you could further explain how the LAMP solution work??

Something like this http://www.easyphp.org/. Just google for apache+mysql+php.
You can install it on the computer you do the development.
Practically you want to look for an AMP solution particular to your OS.
Any way, ultimately you should look for a solution tailored to the web provider you use, if you are tied to a certain provider. If not, then is safe to use (L/W)AMP

LAMP is a standard web server. In what you are attempting to accomplish, it is recognized that the easiest solution is to do it web based. Get a web site, start a database on the MySQL that is on there, get some PHP setup that would do all the handling of the data that is going back and forth. Write a Unity application that contacts the PHP page getting and pushing data as needed. :wink:

Hello all, sorry for the missing action, was busy with other stuff.

I have downloaded the easyphp. How am i going to start using it with Unity?? BigMisterB, you mention that " Get a web site, start a database on the MySQL that is on there, get some PHP setup that would do all the handling of the data that is going back and forth. Write a Unity application that contacts the PHP page getting and pushing data as needed"? I would appreciate if you could please tell me more how can i go about starting it…

Thank you

I would say, do not use a database. The very fact that you have to ask how to use one means its outside your competancy, note a relational database ought to be in 3NF to be queryable. As suggested above XML appears to be a better choice. You could you LINQ to query it without normalizing the data.

Hope that made sense.

I personally like using SQLite.
You can find a basic example here

http://forum.unity3d.com/threads/91352-Data-storage?p=591454&viewfull=1#post591454

You will probably need Unity Pro for it to work and the dll’s will need to go in your Program Files/Unity/Editor folder as well as the project folder.
Hope this helps.

Ok yeah Sqlite is great, but whats the use if you don’t know how to design a database?

Databases are just about completely unnecessary for most game projects. Unless you are building a MMO that needs to process enormous amounts of data, it is much more efficient to simply store your game data in memory without the unnecessary overhead of database software. Databases should only be used when your data set is too large to all be loaded into the user’s memory and thus needs to be quickly transferred to/from a hard disk.
Database queries return strings, whose contents must be parsed into usable objects, and thus add a substantial amount of unnecessary overhead in both performance and development time. Serialization however is directly integrated into the language, and can be used to serialize/unserialize any data structures marked as serializable to/from binary data that may then be saved to a file (add ‘[serializable]’ in front of a class declaration); encrypting/decrypting said file will secure your data from being tampered with. This is the way to add save/load game functionality, as it is possible to create an entirely persistant world using this method - though as Unity doesn’t directly support save game functionality via serialization, it would take a significant amount of programming effort to pull this off. (I should note however that Unity is built around serialization, as this is what makes the editor’s data persistance, fast startup, and excellent performance possible).

Anyhow, back to the OP, the best method to implement simple saving/loading of an array/hashtable of data would be to save it as a text file (or xml), and encrypt/decrypt its contents at runtime. Building a parser to save/load this kind of data to/from a text file should be very easy, and this is by far the simplest solution to your problems. Of course, if you could alternatively use serialization and build an editor script to edit your datafields, but that’s really just unnecessary complexity.
What you should not do is build your game around a full php-run SQL database, and then start wondering why no one else can run it due to lack of a functioning web server installed on their machines. Use php and mySQL to run a web server that connects with a Unity client to provide additional multiplayer services; you do not need to use php -ever- to build a game client. You could use SQLLite (which is actually just an SQL interface to a regular binary file), though it is much less efficient and will require more work to set up than serialization or loading data from a text file.

Hello CrazySi, I am familiar with database. My problem is that i don’t know how database are going to communicate with Unity. After all the setup, i supposedly that everything will be fine. And to add on, this is a requirement. I have to do it this way. Thank you

Hello Xathos, i get what you trying to imply. The main purpose of creating database for my games is because i want to increase the flexibility of my game. Which mean with the use of database, i do not need to hard code all my information and instead use database to do all the dirty work.