• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Advanced Tutorial] MySQL

Status
Not open for further replies.
To start using MySQL within Unity (a server built in unity), you need the MySQL connector.

http://dev.mysql.com/downloads/connector/net/1.0.html#downloads

After the installation, navigate to the installation directory, Assemblies, v2.0, then grab the MySql.data.dll and place it in your Project's plugin folder (if it doesn't exist, create it).

Code:
//First line
import MySql.Data.MySqlClient;
(We import the library)

Now, we need several things.
Let us make a Start() function.

Code:
function Start(){}
Let us think for a second.
We want the server to open up a connection and pass commands.
Alright then.


Code:
function Start(){
var connection = new MySqlConnection("SERVER=SERVERIPGOESHERE;DATABASE=the database you want;UID=username;PASSWORD=repwh***;");
//Basically, we declared the connection we want. You could, of course, make that several strings and change them at will.
}
Connection is set up.

Code:
function Start(){
var connection = new MySqlConnection("SERVER=SERVERIPGOESHERE;DATABASE=the database you want;UID=username;PASSWORD=repwh***;");
//Basically, we declared the connection we want. You could, of course, make that several strings and change them at will.


//Alright.
connection.Open(); // Opens up the connection

//We pull up a command
    var dbcmd : MySqlCommand = MySqlCommand("INSERT BLAH BLAH BLAH", connection);
//And we execute it
    var reader : MySqlDataReader = dbcmd.ExecuteReader();

}
Now, if you want to close a connection, just do a connection.Close();


I am willing to help you out, if you don't get it working by following this tutorial.

TROUBLESHOOTING:

If you are having any errors, change your api compatibility to .net 2 instead of .net 2 subset @ player settings.
 
Level 18
Joined
Mar 7, 2005
Messages
824
look interesting, and kinda strange :D but hey if it works..

I see you want to work with mySQL and databases i guess? Let me see if I find some time today or later on to write a tutorial about this myseld, which includes saving into databases and loading information into unity. It's pretty easy way with c#
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
You network it so that the Client asks the server, and the server performs the queries, silly DSG.
And what stops a client sending out queries to destroy tables? Make new tables? Flood tables? Access data from tables it should not? Or are you trying to say that the client performs remote procedure/function calls that then the server makes and performs the queries?
 
Status
Not open for further replies.
Top