summaryrefslogtreecommitdiff
path: root/Aktywator/MySQL.cs
diff options
context:
space:
mode:
authorMichal Zimniewicz <mzimniew@man.poznan.pl>2015-01-28 10:49:16 +0100
committerMichal Zimniewicz <mzimniew@man.poznan.pl>2015-01-28 10:58:38 +0100
commit29d9771333f9f996208b0e3dbce95dd80cddf8e9 (patch)
tree7160accad1184eabc2dbfadf4175aeeb6abf82dc /Aktywator/MySQL.cs
parenta331533373a95820a89aa93fead351ceb9a30046 (diff)
initial commit with unreleased version 1.0.4
Diffstat (limited to 'Aktywator/MySQL.cs')
-rw-r--r--Aktywator/MySQL.cs90
1 files changed, 90 insertions, 0 deletions
diff --git a/Aktywator/MySQL.cs b/Aktywator/MySQL.cs
new file mode 100644
index 0000000..29b90b5
--- /dev/null
+++ b/Aktywator/MySQL.cs
@@ -0,0 +1,90 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using MySql.Data.MySqlClient;
+using data = MySql.Data.MySqlClient.MySqlDataReader;
+
+namespace Aktywator
+{
+ 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 void query(string query)
+ {
+ MySqlCommand comm = new MySqlCommand(query, conn);
+ comm.ExecuteNonQuery();
+ }
+
+ public string selectOne(string query)
+ {
+ MySqlCommand comm = new MySqlCommand(query, conn);
+ object ob = comm.ExecuteScalar();
+ if (ob != null) return ob.ToString();
+ else return "";
+ }
+
+ public data select(string query)
+ {
+ MySqlCommand comm = new MySqlCommand(query, conn);
+ return comm.ExecuteReader();
+ }
+
+ 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; }
+ }
+}