65 lines
1.5 KiB
C#
65 lines
1.5 KiB
C#
using MySql.Data.MySqlClient;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Articulate
|
|
{
|
|
public class DBConnection
|
|
{
|
|
public string Server { get; set; }
|
|
public string DatabaseName { get; set; }
|
|
public string UserName { get; set; }
|
|
public string Password { get; set; }
|
|
|
|
public MySqlConnection Connection { get; set; }
|
|
|
|
private static DBConnection _instance = null;
|
|
public static DBConnection Instance()
|
|
{
|
|
if (_instance == null)
|
|
_instance = new DBConnection();
|
|
return _instance;
|
|
}
|
|
|
|
public bool IsConnect()
|
|
{
|
|
if (Connection == null)
|
|
{
|
|
if (String.IsNullOrEmpty(DatabaseName))
|
|
return false;
|
|
string connstring = string.Format("Server={0}; database={1}; UID={2}; password={3}; SSL Mode=none", Server, DatabaseName, UserName, Password);
|
|
Connection = new MySqlConnection(connstring);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public void SendCommand(MySqlCommand command)
|
|
{
|
|
Connection.Open();
|
|
|
|
command.ExecuteNonQuery();
|
|
|
|
Connection.Close();
|
|
}
|
|
|
|
public void SendQuery(MySqlCommand query)
|
|
{
|
|
Connection.Open();
|
|
|
|
using (MySqlDataReader reader = query.ExecuteReader())
|
|
{
|
|
|
|
}
|
|
|
|
Connection.Close();
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
Connection.Close();
|
|
}
|
|
}
|
|
}
|