123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System;
- using MySql.Data.MySqlClient;
- namespace HyperCube
- {
- public class MySQLConnector
- {
- private MySQLConnector(){}
- private readonly string Server = "dmatter.net";
- private readonly string DatabaseName = "documents";
- private readonly string UserName = "promsystem";
- private readonly string Password = "PrmSystem212";
- MySqlCommand SQLcom;
- public MySqlConnection Connection { get; set; }
- private static MySQLConnector _instance = null;
- public static MySQLConnector Instance()
- {
- if (_instance == null)
- _instance = new MySQLConnector();
- return _instance;
- }
- public bool IsConnect()
- {
- if (Connection == null)
- {
- if (String.IsNullOrEmpty(DatabaseName))
- return false;
-
- string connstring = $"Server={Server}; database={DatabaseName}; UID={UserName}; password={Password}";
- Connection = new MySqlConnection(connstring);
- Connection.Open();
- }
- return true;
- }
- public long SQLInsert(string sql)
- {
- long lastID = 0;
- bool connected = IsConnect();
- if (connected)
- {
- SQLcom = new(sql, Connection);
- SQLcom.ExecuteNonQuery();
- SQLcom.Dispose();
- lastID = SQLcom.LastInsertedId;
- }
- return lastID;
- }
- public uint SQLGetID(string sql)
- {
- bool connected = IsConnect();
- if (connected)
- {
- SQLcom = new(sql, Connection);
- object obj = SQLcom.ExecuteScalar();
- return (uint)obj;
- }
- else return 0;
- }
- public void Close()
- {
- Connection.Close();
- }
- }
- }
|