C# で再利用可能な MySQL データベース クラスを作成しようとしていますが、セキュリティを維持することが心配です (ビジネスでの使用の可能性)。私は多くの読書をしてきましたが、パラメーターを使用してテーブルにデータを追加したり、フェッチしたりすることをお勧めします。私の問題は、さまざまなテーブルを通じてクラスを再利用可能に保つことです現在の挿入方法(データベースクラス内):
public void Insert(string incomingQuery) //Insert Statement
{
//Assign the incomingQuery for use.
string query = incomingQuery;
//Open Database Connection
if(this.OpenConnection() == true)
{
//Create command and assign the query and connection from the constructor
MySqlCommand command = new MySqlCommand(query, connection);
//Execute the command
command.ExecuteNonQuery();
//Close the connection
this.CloseConnection();
}
}
そして、Create
別のクラスから SQL クエリを渡す私のメソッド ( Users
):
public void Create()
{
//Add a new user to the database
string sqlQuery = "INSERT INTO Users(first_name, last_name, pc_username) VALUES('" + firstName + "','" + lastName + "','" + userName + "');";
database.Insert(sqlQuery);
Login();
}
これをより安全にするにはどうすればよいですか?