Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System;
- using System.Data;
- using System.Text;
- using System.Collections;
- using System.Collections.Generic;
- using System.Security.Cryptography;
- using MySql.Data;
- using MySql.Data.MySqlClient;
- public class MysqlManager : MonoBehaviour {
- //Manager
- public GuiManager _GuiManager;
- public string host, database, user, password;
- public bool pooling = true;
- private string connectionString;
- private string CommandString;
- private MySqlConnection con = null;
- private MySqlDataReader rdr = null;
- private bool AccountExist;
- void Awake(){
- DontDestroyOnLoad (this.gameObject);
- connectionString = "Server="+host+";Database="+database+";User="+user+";Password="+password+";Pooling=";
- if(pooling){
- connectionString += "true;";
- }else{
- connectionString += "false;";
- }
- }
- void MysqlConnect(){
- try {
- con = new MySqlConnection(connectionString);
- con.Open();
- Debug.Log("Mysql State: " +con.State);
- }catch (Exception e){
- Debug.Log(e);
- }
- }
- void OnApplicationQuit(){
- if (con != null) {
- if (con.State.ToString () != "Closed") {
- con.Close ();
- Debug.Log ("Mysql connection close");
- }
- }
- }
- public void _AccountCreat(String username, String Password, String email){
- CheckIfAccountExist(username, email);
- if (AccountExist == false) {
- MysqlConnect ();
- CommandString = "INSERT INTO users (username, password, email) VALUES ('" + username + "', '" + Password +"', '" + email+"')";
- MySqlCommand cmd = new MySqlCommand (CommandString, con);
- cmd.ExecuteNonQuery ();
- MysqlClose ();
- }
- }
- void CheckIfAccountExist(String username, String email){
- MysqlConnect ();
- CommandString = "SELECT COUNT(*) FROM users WHERE 'username' = '"+username+"' OR 'email' = '"+email+"'";
- MySqlCommand cmd = new MySqlCommand (CommandString, con);
- cmd.ExecuteNonQuery ();
- MysqlClose ();
- }
- void MysqlClose(){
- try {
- con.Close();
- Debug.Log ("Mysql connection close");
- }catch (Exception e){
- Debug.Log(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement