- Home /
Database in unity 3d
In my game whenever user opens the game , it should fetch value from a url
void Start () {
string url = "http:/myurl";
WWW www = new WWW(url);
StartCoroutine(WaitForRequest(www));
}
IEnumerator WaitForRequest(WWW www)
{
yield return www;
// check for errors
if (www.error == null)
{
Debug.Log("WWW Ok!: " + www.data);
} else {
Debug.Log("WWW Error: "+ www.error);
}
}
I want to save this data in database to use in game.
I am not aware of databse in unity.
Which is the best method for it .
i only know about PlayerPrefab. Any other good method exist?
If user is not connected he should play with already saved data in mobile. Need good advice and solution ?
There are a number of SQL products on the Asset Store.
You (or anyone reading who's a beginner) will have to learn SQL database program$$anonymous$$g, at least in a simple way, if you want to use a database.
There's really nothing wrong with using PlayerPrefs for even quite a lot of data .. why not?
Tip - use Secured PlayerPrefs (asset store) for any real-life project.
How to make a new database/table and insert values into it
Answer by Mexallon · May 13, 2013 at 06:24 AM
Hej there. If you want a small database with not much of a content and without necesarrily internet connectivity I recommend you Sqlite. This is just a file that contains the data but you can access it just like normal SQL.
There are some free Plugins available I used it a while ago and it worked well in Unity
Yeah sure. Take a look at this project at github. Just add the class to your project then you should be able to create a sqlitedatabase class and send queries to it. If you dont have a clue about SQL syntax and usage yet you should catch up that first before using sql.
create a new c# script, copy this in and add it to your camera. should work
public class Sqlite : $$anonymous$$onoBehaviour {
private SqliteDatabase db;
void Start(){
db = new SqliteDatabase("database_name_here_with_extension");
db.ExecuteQuery("SELECT * FRO$$anonymous$$ table_name;");
}
}
Put the sqlitedatabase.cs file and everything you've downlaoded from the github page into a folder named "Plugins" in your Assets folder. If it doesnt exist already create it.
$$anonymous$$y bad. the name of the method is ExecuteQuery not just query
should i create database using query
you could. but use another script/project for that. but more comfortable is to use a client to do this. Under OSX iam using "SQLite$$anonymous$$anager" for example
where i have to add db name and column name.please explain.
the name of the db is the parameter for the constructor (in my example above "database_name_here_with_extension" The column name is part of the query, in my example "*" it could also be "id" or "id, name"
Answer by Ebil · May 13, 2013 at 07:36 AM
For simple usage you can call a PHP script thats accessing the database. But I think that wouldnt be so secure.
Your answer
![](https://koobas.hobune.stream/wayback/20220613102123im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity3d and Database and MultiPlayer Games 1 Answer
Umlaute missing in Unity GUI. 1 Answer
Problem in starting mysqld Process 0 Answers
MySql Online Character About 0 Answers
Unity 3D and Databases? 1 Answer