Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using MySql.Data.MySqlClient;
- using System;
- using System.Collections.Generic;
- using Impinj.OctaneSdk;
- using UnityEngine.UI;
- public class MySqlConnectionScript : MonoBehaviour {
- private static MySqlConnectionScript _instnace;
- public static MySqlConnectionScript sharedInstance()
- {
- return _instnace;
- }
- static string row = "";
- public string host = "***";
- public string database = "*****";
- public string usrename = "*****";
- public string password = "******";
- public List<AppUser> users = new List<AppUser>();
- AppUser user;
- public bool connectionEstablished = false;
- // Use this for initialization
- void Awake () {
- _instnace = this;
- GetDataFromDatabase();
- }
- // Download all of the data from the Database
- public string GetDataFromDatabase()
- {
- string myConnectionString = "Server=" + host + ";Database=" + database + ";Uid=" + usrename + ";Pwd=" + password + ";";
- using (MySqlConnection connection = new MySqlConnection(myConnectionString))
- {
- MySqlCommand command = connection.CreateCommand();
- command.CommandText = "SELECT * FROM Users";
- MySqlDataReader Reader;
- try
- {
- connection.Open();
- Reader = command.ExecuteReader();
- while (Reader.Read())
- {
- // fill my class with the data taken from the Database
- user = new AppUser(Reader.GetString("UserName").Trim(), Reader.GetString("RFID_Tag").Trim());
- users.Add(user);
- }
- connectionEstablished = true;
- }
- catch (Exception x)
- {
- Debug.Log(x.Message);
- return x.Message;
- }
- connection.Close();
- return row;
- }
- }
- }
- public class AppUser
- {
- public string username { get; set; }
- public string rfid { get; set; }
- public AppUser(string _name, string _rfid)
- {
- username = _name;
- rfid = _rfid;
- }
- public void SetUserName(string _userName) { username = _userName; }
- public void SetRFID(string _rfid) { rfid = _rfid; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement