Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Pluton
- {
- using System;
- using MySql.Data.MySqlClient;
- public class Storage
- {
- private MySqlConnection Conn;
- private static Storage instance;
- public static Storage GetInstance()
- {
- if (instance == null)
- instance = new Storage();
- return instance;
- }
- public MySqlConnection Connect(string host, string user, string db, string port, string pass)
- {
- MySqlConnection connection;
- try
- {
- connection = new MySqlConnection(String.Format("server={0};user={1};database={2};port={3};password={4};", host, user, db, port, pass));
- connection.Open();
- Logger.LogDebug("MySql Connection Opened.");
- return connection;
- }
- catch (Exception ex)
- {
- Logger.LogError("Could not Connect to MySQL Server");
- Logger.LogException(ex);
- return new MySqlConnection();
- }
- }
- public object Query(string query, MySqlConnection Conn)
- {
- MySqlDataReader dr;
- try
- {
- MySqlCommand cmd = new MySqlCommand(query, Conn);
- dr = cmd.ExecuteReader();
- }
- catch (Exception ex)
- {
- Logger.LogError("MySql Query Error");
- Logger.LogException(ex);
- return false;
- }
- return dr;
- }
- public object QueryCount(string query, MySqlConnection Conn)
- {
- object data;
- try
- {
- MySqlCommand cmd = new MySqlCommand(query, Conn);
- data = cmd.ExecuteScalar();
- if (data != null)
- int d = Convert.ToInt32(data);
- }
- catch (Exception ex)
- {
- Logger.LogError("MySql Query Count Error");
- Logger.LogException(ex);
- return false;
- }
- return data;
- }
- public bool Insert(string query, MySqlConnection Conn)
- {
- int inst;
- try
- {
- MySqlCommand cmd = new MySqlCommand(query, Conn);
- inst = cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Logger.LogError("MySql Insert Error");
- Logger.LogException(ex);
- return false;
- }
- if (inst > 0)
- return true;
- else
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment