链接数据库,可以分为以下几个流程:
链接MySQL(数据库地址、端口、用户名、密码)
选择数据库
执行sql语句
关闭数据库
转换为代码如下:
using System;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data;
using System.Text.RegularExpressions;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO; public class DataMgr {
MySqlConnection sqlConn; public static DataMgr instance;
public DataMgr(){
instance = this;
Connect();
} public void Connect() {
string connStr = "Database=game;Data Source=127.0.0.1;";
connStr += "User Id=root;Password=123456;port=3306";
sqlConn = new MySqlConnection(connStr);
try
{
sqlConn.Open();
}
catch (Exception e) {
Console.Write("[DataMgr]Connect " + e.Message);
return;
}
}
}
明天写放置sql注入~