mirror of
https://git.battle-of-pip.de/root/vpr-mitarbeiterverwaltung.git
synced 2025-12-13 22:31:38 +01:00
added mysql connection
This commit is contained in:
@@ -12,11 +12,13 @@ namespace Server
|
||||
private MySqlConnection _connection;
|
||||
private MessageSender ms;
|
||||
|
||||
public MySQL(string username, string password, string server, string database, MessageSender ms)
|
||||
|
||||
public MySQL(string username, string password, string server, string port, string database, MessageSender ms)
|
||||
{
|
||||
this.ms = ms;
|
||||
ms.Log("[MySQL] Initializing connection...");
|
||||
string connectionString = $"Server={server};Database={database};User ID={username};Password={password};";
|
||||
// include port in the connection string:
|
||||
string connectionString = $"Server={server};Port={port};Database={database};User ID={username};Password={password};";
|
||||
_connection = new MySqlConnection(connectionString);
|
||||
ms.Log("[MySQL] Connection to database...");
|
||||
|
||||
@@ -51,7 +53,24 @@ namespace Server
|
||||
_ => "b"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a non‐query SQL statement (e.g. CREATE TABLE, ALTER, etc.).
|
||||
/// Returns null on success, or an error JSON if it fails.
|
||||
/// </summary>
|
||||
public string ExecuteNonQuery(string sql)
|
||||
{
|
||||
using var cmd = new MySqlCommand(sql, _connection);
|
||||
try
|
||||
{
|
||||
cmd.ExecuteNonQuery();
|
||||
return JsonResponse(new { success = true });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return JsonResponse($"Execute failed: {ex.Message}", true);
|
||||
}
|
||||
}
|
||||
|
||||
public string Insert(string table, Dictionary<string, object> data)
|
||||
{
|
||||
string columns = string.Join(", ", data.Keys);
|
||||
|
||||
Reference in New Issue
Block a user