Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USING UnityEngine;
- USING System;
- USING System.Collections;
- USING System.DATA;
- USING System.DATA.SQL;
- USING System.DATA.SqlClient;
- public class SQLDatabase : MonoBehaviour {
- // Global VARIABLES
- private static IDbConnection dbConnection;
- public static FLOAT dollars;
- public static FLOAT Lodging;
- public static FLOAT Vehicles;
- // Initialisation
- public void OnEnable() {
- Debug.Log("SQLDatabase.Awake()");
- openSqlConnection();
- //displayBank();
- }
- // CONNECT TO DATABASE
- private static void openSqlConnection() {
- string connectionString = "Data source = localhost\\DEVILSZONE\\SQLEXPRESS;" +
- "Database=safariville;" +
- "Integrated security=True;"+
- "Pooling=false;";
- dbConnection = NEW SqlConnection(connectionString);
- dbConnection.OPEN();
- Debug.Log("DATABASE connected");
- }
- // MySQL Query
- public static void displayBank()
- {
- try
- {
- IDbCommand dbCommand = dbConnection.CreateCommand();
- dbCommand.CommandText = "SELECT * FROM safariville.dbo.bank WHERE SCash = 3000.00";
- Debug.Log("SELECT executed");
- IDataReader reader = dbCommand.ExecuteReader();
- // Executing OR Getting the DATA FROM the databse
- while (reader.READ())
- {
- dollars = reader.GetFloat(0);
- Lodging = reader.GetFloat(3);
- Debug.Log("bank: " + Lodging);
- Vehicles = reader.GetFloat(4);
- Debug.Log("bank: " + Vehicles);
- }
- reader.Close();
- reader = NULL;
- dbCommand.Dispose();
- dbCommand = NULL;
- }
- catch (Exception ex) {
- Debug.Log(ex);
- }
- }
- // Disconnect FROM DATABASE
- private static void closeSqlConnection()
- {
- dbConnection.Close();
- dbConnection = NULL;
- }
- // ON quit
- public void OnApplicationQuit()
- {
- closeSqlConnection();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement