diff options
author | emkael <emkael@tlen.pl> | 2018-10-12 20:43:25 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2018-10-12 20:43:25 +0200 |
commit | 0550305e3f1f2558588b6b87a8c1b4004437ad3b (patch) | |
tree | 7e3ceec0e7b805fdd937535672ce16beffef9b31 /kurier/MySQL.cs | |
parent | 8465d82288402eacf28cba9cff5c29e798005408 (diff) |
MySQL settings
Diffstat (limited to 'kurier/MySQL.cs')
-rw-r--r-- | kurier/MySQL.cs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/kurier/MySQL.cs b/kurier/MySQL.cs new file mode 100644 index 0000000..cafb5c8 --- /dev/null +++ b/kurier/MySQL.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Text; +using MySql.Data.MySqlClient; + +namespace kurier +{ + public class MySQL + { + private MySqlConnection conn; + private string database; + + public MySQL(string database) + { + this.database = database; + connect(); + } + + public void connect() + { + conn = new MySqlConnection((database != "" ? ("Database=" + database + ";") : "") + + "Data Source=" + getHost() + ";User Id=" + getUser() + ";Password=" + getPass() + + ";Port=" + getPort() + ";charset=utf8;"); + + conn.Open(); + } + + public void close() + { + try + { + conn.Close(); + conn = null; + } + catch (Exception) + { + } + } + + public bool isOpen() + { + return conn != null; + } + + public static string test() + { + try + { + MySqlConnection conn = new MySqlConnection("Data Source=" + getHost() + ";User Id=" + getUser() + ";Password=" + getPass() + + ";Port=" + getPort() + ";charset=utf8;"); + conn.Open(); + } + catch (MySqlException e) + { + return e.Message; + } + catch (Exception e) + { + return "Prawdopodobnie brakuje Ci dll-ki od MySQL'a.\n\n" + e.Message; + } + return ""; + } + + public static string getHost() { return Properties.Settings.Default.HOST; } + public static string getUser() { return Properties.Settings.Default.USER; } + public static string getPass() { return Properties.Settings.Default.PASS; } + public static string getPort() { return Properties.Settings.Default.PORT; } + public static bool getConfigured() { return Properties.Settings.Default.CONFIGURED; } + } +} |