Advertisement
Guest User

Untitled

a guest
May 28th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3. using System.Data;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Security.Cryptography;
  8. using MySql.Data;
  9. using MySql.Data.MySqlClient;
  10.  
  11.  
  12.  
  13. public class MysqlManager : MonoBehaviour {
  14.  
  15. //Manager
  16. public GuiManager _GuiManager;
  17.  
  18. public string host, database, user, password;
  19. public bool pooling = true;
  20.  
  21. private string connectionString;
  22. private string CommandString;
  23. private MySqlConnection con = null;
  24. private MySqlDataReader rdr = null;
  25.  
  26. private bool AccountExist;
  27.  
  28. void Awake(){
  29. DontDestroyOnLoad (this.gameObject);
  30. connectionString = "Server="+host+";Database="+database+";User="+user+";Password="+password+";Pooling=";
  31. if(pooling){
  32. connectionString += "true;";
  33. }else{
  34. connectionString += "false;";
  35. }
  36. }
  37.  
  38. void MysqlConnect(){
  39. try {
  40. con = new MySqlConnection(connectionString);
  41. con.Open();
  42. Debug.Log("Mysql State: " +con.State);
  43. }catch (Exception e){
  44. Debug.Log(e);
  45. }
  46. }
  47.  
  48. void OnApplicationQuit(){
  49. if (con != null) {
  50. if (con.State.ToString () != "Closed") {
  51. con.Close ();
  52. Debug.Log ("Mysql connection close");
  53. }
  54. }
  55. }
  56.  
  57. public void _AccountCreat(String username, String Password, String email){
  58. CheckIfAccountExist(username, email);
  59. if (AccountExist == false) {
  60. MysqlConnect ();
  61. CommandString = "INSERT INTO users (username, password, email) VALUES ('" + username + "', '" + Password +"', '" + email+"')";
  62. MySqlCommand cmd = new MySqlCommand (CommandString, con);
  63. cmd.ExecuteNonQuery ();
  64. MysqlClose ();
  65. }
  66.  
  67. }
  68.  
  69. void CheckIfAccountExist(String username, String email){
  70. MysqlConnect ();
  71. CommandString = "SELECT COUNT(*) FROM users WHERE 'username' = '"+username+"' OR 'email' = '"+email+"'";
  72. MySqlCommand cmd = new MySqlCommand (CommandString, con);
  73. cmd.ExecuteNonQuery ();
  74. MysqlClose ();
  75. }
  76.  
  77. void MysqlClose(){
  78. try {
  79. con.Close();
  80. Debug.Log ("Mysql connection close");
  81. }catch (Exception e){
  82. Debug.Log(e);
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement