religion/Assets/MySQL/GetSQL.cs

52 lines
1.4 KiB
C#
Raw Normal View History

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)
{
e.ToString();//解决Warming
Debug.Log("连接失败");
}
MySqlCommand cmd = new MySqlCommand(SQLstatement, con);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
data.Add(reader.GetString(datalist).ToString());
}
return data;
}
}