Артем Кошелев
Знаток
(269)
1 год назад
Держи пример, если поможет
using System.Data;
using System.Data.SqlClient;
public class MySQLConnection : MonoBehaviour {
private MySqlConnection connection;
private string server;
private string database;
private string uid;
private string password;
void Start() {
server = "localhost";
database = "mydatabase";
uid = "myusername";
password = "mypassword";
string connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);
OpenConnection();
}
private void OpenConnection() {
if (connection.State == ConnectionState.Closed) {
connection.Open();
}
}
private void CloseConnection() {
if (connection.State == ConnectionState.Open) {
connection.Close();
}
}
private void ExecuteQuery(string query) {
if (connection.State == ConnectionState.Open) {
MySqlCommand cmd = new MySqlCommand(query, connection);
cmd.ExecuteNonQuery();
}
}
void Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
string query = "INSERT INTO mytable (name, score) VALUES ('Player1', 100)";
ExecuteQuery(query);
CloseConnection();
}
}
}
Можете пожалуйста, объяснить в виде небольшой инструкции правильного подключения MySQL к Unity. Желательно с кодом C#