Advertisement
Guest User

Untitled

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