- Joined
- Jul 9, 2008
- Messages
- 2,555
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).
(We import the library)
Now, we need several things.
Let us make a Start() function.
Let us think for a second.
We want the server to open up a connection and pass commands.
Alright then.
Connection is set up.
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.
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;
Now, we need several things.
Let us make a Start() function.
Code:
function Start(){}
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.
}
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();
}
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.