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

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
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