1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
class MYSQL
{
private MySqlConnection ConnectionID;
private string DBName;
private string Server;
private string Login;
private string Password;
private bool dbUp = false;
//******************* Accesseurs de lecture *********************
public MySqlConnection getConnectionID() { return this.ConnectionID; }
public bool getDbUp() { return this.dbUp; }
//******************* Accesseurs d'écriture *********************
public void setParametreConnexion(string server, string login, string pass, string db)
{
this.Server = server;
this.Login = login;
this.Password = pass;
this.DBName = db;
}
//******************* Méthodes publics **************************
//--- Connexion à une base
public bool SQLConnect()
{
string connectionString = "Server=" + this.Server +
";Database=" + this.DBName +
";User ID=" + this.Login +
";Password=" + this.Password + ";";
try
{
this.ConnectionID = new MySqlConnection(connectionString);
Console.WriteLine("Ouverture de la connexion" );
this.ConnectionID.Open();
Console.WriteLine("Connexion ouverte" );
this.dbUp = true;
return true;
}
catch (MySqlException myEx)
{
Console.WriteLine("ERROR " + myEx.GetType() + " : Impossible de se connecter à la base de donnée." );
this.dbUp = false;
return false;
}
}
} |
Partager