Created
December 22, 2016 22:12
-
-
Save JKamsker/a6f1a7323fec3c4dd0e43e9e2263ebbd to your computer and use it in GitHub Desktop.
Base Structure for a mysql provider class - Prettier .tostring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MySql.Data.MySqlClient; | |
namespace MediaProviderWorker.Helpers.Database | |
{ | |
class MysqlConnectionData | |
{ | |
public string Server { get { return _server; }set { _server = value; } } | |
public string Port { get { return _port; }set { _port = value; } } | |
public string Db { get { return _db; }set { _db = value; } } | |
public string User { get { return _user; }set { _user = value; } } | |
public string Password { get { return _password; }set { _password = value; } } | |
public bool Pooling { get { return _pooling; }set { _pooling = value; } } | |
string _server; | |
string _port; | |
string _db; | |
string _user; | |
string _password; | |
bool _pooling; | |
public MysqlConnectionData() { } | |
public MysqlConnectionData(string server, string db, string user, string password = "", string port = "3306", bool pooling = false) | |
{ | |
_server = server; | |
_port = port; | |
_db = db; | |
_user = user; | |
_password = password; | |
_pooling = pooling; | |
} | |
public override string ToString() | |
{ | |
return string.Format("Server={0};Port={1};Database={2};User ID={3};Password={4};Pooling={5}", _server, _port, _db, _user, _password, (_pooling ? "true" : "false")); | |
} | |
} | |
class MysqlProvider | |
{ | |
MySqlConnection dbcon = null; | |
public MysqlProvider(MysqlConnectionData ConnectionData) | |
{ | |
dbcon = new MySqlConnection(ConnectionData.ToString()); | |
dbcon.Open(); | |
} | |
~MysqlProvider() | |
{ | |
dbcon.Close(); | |
dbcon = null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment