Created
January 8, 2013 02:03
-
-
Save jerieljan/4480439 to your computer and use it in GitHub Desktop.
This file contains 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
// Copyright 2008 - Team Servo | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Data; | |
using System.Data.Sql; | |
using System.Data.SqlClient; | |
using MySql.Data.MySqlClient; | |
namespace ProjectServo.Models | |
{ | |
public class MySQLHandler | |
{ | |
//TODO: Put this away here. This is only temporary. | |
private static string connectionString = "server=127.0.0.1;uid=servo-user;pwd=projectservo;database=project_servo;"; | |
private static MySqlConnection conn = new MySqlConnection(); | |
//Performs a connection to the database | |
public static void connect() | |
{ | |
conn.ConnectionString = connectionString; | |
conn.Open(); | |
} | |
//Sends a one-way query to the MySQL database. Returns false upon error | |
public static void push(string query) | |
{ | |
connect(); | |
MySqlCommand com = new MySqlCommand(); | |
com.Connection = conn; | |
com.CommandText = query; | |
try | |
{ | |
com.ExecuteNonQuery(); | |
} | |
finally | |
{ | |
close(); | |
} | |
} | |
public static DataTable pull(string query) | |
{ | |
connect(); | |
MySqlDataAdapter data = new MySqlDataAdapter(query,conn); | |
DataTable result = new DataTable(); | |
try | |
{ | |
data.Fill(result); | |
data.Dispose(); | |
} | |
finally | |
{ | |
close(); | |
} | |
return result; | |
} | |
public static void close() | |
{ | |
conn.Close(); | |
} | |
//Automatically adds an entry for the changelog. | |
public static void report(string description) | |
{ | |
try | |
{ | |
//push(String.Format("INSERT INTO `projectservo`.`changelog` (`Log_Description`) VALUES ('{0}');", description)); | |
} | |
catch (Exception) | |
{ | |
//Do nothing | |
} | |
} | |
//TODO: Implement two-way queries (resultset) and transaction support. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment