
commit de8d79b73e560814ff9fc8a0c3418009682c5ef8 Author: SAIPO <grasste0403@hotmail.com> Date: Tue Nov 23 21:25:44 2021 +0800 任务:搭建Mysql数据库相关框架 1.完成Mysql动态链接库的导入 2.实现基本的服务器连接数据框架 3.实现Sql语句查询框架
51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using MySql.Data.MySqlClient;
|
|
using UnityEngine;
|
|
|
|
|
|
public class GetSQL : MonoBehaviour
|
|
{
|
|
public DataScriptableObject dataScriptableObject;
|
|
|
|
private string LinkInfo;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
LinkInfo = "server="+dataScriptableObject.IP+";" +
|
|
"port="+dataScriptableObject.Port+";" +
|
|
"database="+dataScriptableObject.Database+";" +
|
|
"user="+dataScriptableObject.User+";" +
|
|
"password="+dataScriptableObject.Password+";" +
|
|
"charset="+dataScriptableObject.Charset;
|
|
}
|
|
|
|
|
|
public List<string> GetSqlData(string SQLstatement, string datalist)
|
|
{
|
|
List<string> data = new List<string>();
|
|
data.Clear();
|
|
MySqlConnection con = new MySqlConnection(LinkInfo);
|
|
try
|
|
{
|
|
con.Open();
|
|
Debug.Log("连接成功");
|
|
}
|
|
catch (MySqlException e)
|
|
{
|
|
Debug.Log("连接失败");
|
|
}
|
|
|
|
MySqlCommand cmd = new MySqlCommand(SQLstatement, con);
|
|
MySqlDataReader reader = cmd.ExecuteReader();
|
|
while (reader.Read())
|
|
{
|
|
data.Add(reader.GetString(datalist).ToString());
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
}
|