Advertisement
Guest User

Untitled

a guest
Jul 4th, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using MySql.Data.MySqlClient;
  4. using System;
  5. using System.Collections.Generic;
  6. using Impinj.OctaneSdk;
  7. using UnityEngine.UI;
  8.  
  9. public class MySqlConnectionScript : MonoBehaviour {
  10.  
  11. private static MySqlConnectionScript _instnace;
  12. public static MySqlConnectionScript sharedInstance()
  13. {
  14. return _instnace;
  15. }
  16.  
  17. static string row = "";
  18.  
  19. public string host = "***";
  20. public string database = "*****";
  21. public string usrename = "*****";
  22. public string password = "******";
  23.  
  24. public List<AppUser> users = new List<AppUser>();
  25.  
  26. AppUser user;
  27.  
  28. public bool connectionEstablished = false;
  29.  
  30. // Use this for initialization
  31. void Awake () {
  32.  
  33. _instnace = this;
  34.  
  35. GetDataFromDatabase();
  36.  
  37. }
  38.  
  39.  
  40. // Download all of the data from the Database
  41. public string GetDataFromDatabase()
  42. {
  43. string myConnectionString = "Server=" + host + ";Database=" + database + ";Uid=" + usrename + ";Pwd=" + password + ";";
  44.  
  45.  
  46. using (MySqlConnection connection = new MySqlConnection(myConnectionString))
  47. {
  48. MySqlCommand command = connection.CreateCommand();
  49. command.CommandText = "SELECT * FROM Users";
  50. MySqlDataReader Reader;
  51. try
  52. {
  53. connection.Open();
  54. Reader = command.ExecuteReader();
  55.  
  56.  
  57. while (Reader.Read())
  58. {
  59. // fill my class with the data taken from the Database
  60. user = new AppUser(Reader.GetString("UserName").Trim(), Reader.GetString("RFID_Tag").Trim());
  61.  
  62. users.Add(user);
  63.  
  64. }
  65.  
  66. connectionEstablished = true;
  67. }
  68. catch (Exception x)
  69. {
  70. Debug.Log(x.Message);
  71. return x.Message;
  72. }
  73.  
  74. connection.Close();
  75. return row;
  76. }
  77.  
  78. }
  79.  
  80. }
  81.  
  82. public class AppUser
  83. {
  84.  
  85. public string username { get; set; }
  86. public string rfid { get; set; }
  87.  
  88. public AppUser(string _name, string _rfid)
  89. {
  90. username = _name;
  91. rfid = _rfid;
  92. }
  93.  
  94. public void SetUserName(string _userName) { username = _userName; }
  95. public void SetRFID(string _rfid) { rfid = _rfid; }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement