代码我也提交一下
using UnityEngine;
using System;
using System.Collections;
using System.Data;
using MySql.Data.MySqlClient;
using System.Collections.Generic;
using MySql.Data;
using System.IO;
using System.Net.NetworkInformation;
public class CMySql : MonoBehaviour {
public static MySqlConnection dbConnection;//Just like MyConn.conn in StoryTools before
static string host = "************";
static string id = "********"; //***不要变***
static string pwd = "*********"; //密码
static string database = "*******";//数据库名
static string result = "";
static string userimei="";
static string userimei_android="";
static string userimei_android2="";
private string strCommand = "Select id from userdata ;";
public static DataSet MyObj;
void Start () {
gameObject.SetActive(false);
//{
//host = GUILayout.TextField( host, 200, GUILayout.Width(200));
//id = GUILayout.TextField( id, 200, GUILayout.Width(200));
//pwd = GUILayout.TextField( pwd, 200, GUILayout.Width(200));
//if(GUILayout.Button("Test"))
//{
string connectionString = string.Format("Server = {0}; Database = {1}; User ID = {2}; Password = {3};",host,database,id,pwd);
openSqlConnection(connectionString);
MyObj = GetDataSet(strCommand);
//读取数据函数
ReaderData();
//}
//GUILayout.Label(result);
}
// On quit
public static void OnApplicationQuit()
{
closeSqlConnection();
}
// Connect to database
private static void openSqlConnection(string connectionString)
{
dbConnection = new MySqlConnection(connectionString);
dbConnection.Open();
result = dbConnection.ServerVersion; //获得MySql的版本
}
// Disconnect from database
private static void closeSqlConnection()
{
dbConnection.Close();
dbConnection = null;
}
// MySQL Query
public static void doQuery(string sqlQuery)
{
IDbCommand dbCommand = dbConnection.CreateCommand();
dbCommand.CommandText = sqlQuery;
IDataReader reader = dbCommand.ExecuteReader();
reader.Close();
reader = null;
dbCommand.Dispose();
dbCommand = null;
}
#region Get DataSet
public DataSet GetDataSet(string sqlString)
{
DataSet ds = new DataSet();
try
{
MySqlDataAdapter da = new MySqlDataAdapter(sqlString, dbConnection);
da.Fill(ds);
}
catch (Exception ee)
{
throw new Exception("SQL:" + sqlString + "\n" + ee.Message.ToString());
}
return ds;
}
#endregion
//读取数据函数
void ReaderData()
{
//IOS PC IMEI
NetworkInterface[] n = NetworkInterface.GetAllNetworkInterfaces();
userimei = n [0].GetPhysicalAddress().ToString();
//end
userimei_android=SystemInfo.deviceName;
userimei_android2 = SystemInfo.deviceUniqueIdentifier;
MySqlCommand mySqlCommand = new MySqlCommand ("Select * from userdata where uid='"+userimei+"' or uid2='"+userimei_android+"' or uid3='"+userimei_android2+"';", dbConnection);
//MySqlCommand mySqlCommand = new MySqlCommand ("Select * from userdata where uid='Daventh' or uid2='"+userimei_android+"';", dbConnection);
MySqlDataReader reader = mySqlCommand.ExecuteReader ();
if (reader.Read()) {
print ("ID:" + reader.GetInt32 (0) + "--IMEI:" + reader.GetString (1) + "--CID:" + reader.GetString (2));
gameObject.SetActive (false);
//gameObject.SetActive (true);
print (userimei + "||||" + userimei_android+"|||||"+userimei_android2);
//Time.timeScale=0;
} else {
gameObject.SetActive (true);
//gameObject.SetActive (false);
print ("mac-----"+userimei);
print ("macandroid-----"+userimei_android);
}
reader.Close();
}
}
using UnityEngine;
using System;
using System.Collections;
using System.Data;
using MySql.Data.MySqlClient;
using System.Collections.Generic;
using MySql.Data;
using System.IO;
using System.Net.NetworkInformation;
public class CMySql : MonoBehaviour {
public static MySqlConnection dbConnection;//Just like MyConn.conn in StoryTools before
static string host = "************";
static string id = "********"; //***不要变***
static string pwd = "*********"; //密码
static string database = "*******";//数据库名
static string result = "";
static string userimei="";
static string userimei_android="";
static string userimei_android2="";
private string strCommand = "Select id from userdata ;";
public static DataSet MyObj;
void Start () {
gameObject.SetActive(false);
//{
//host = GUILayout.TextField( host, 200, GUILayout.Width(200));
//id = GUILayout.TextField( id, 200, GUILayout.Width(200));
//pwd = GUILayout.TextField( pwd, 200, GUILayout.Width(200));
//if(GUILayout.Button("Test"))
//{
string connectionString = string.Format("Server = {0}; Database = {1}; User ID = {2}; Password = {3};",host,database,id,pwd);
openSqlConnection(connectionString);
MyObj = GetDataSet(strCommand);
//读取数据函数
ReaderData();
//}
//GUILayout.Label(result);
}
// On quit
public static void OnApplicationQuit()
{
closeSqlConnection();
}
// Connect to database
private static void openSqlConnection(string connectionString)
{
dbConnection = new MySqlConnection(connectionString);
dbConnection.Open();
result = dbConnection.ServerVersion; //获得MySql的版本
}
// Disconnect from database
private static void closeSqlConnection()
{
dbConnection.Close();
dbConnection = null;
}
// MySQL Query
public static void doQuery(string sqlQuery)
{
IDbCommand dbCommand = dbConnection.CreateCommand();
dbCommand.CommandText = sqlQuery;
IDataReader reader = dbCommand.ExecuteReader();
reader.Close();
reader = null;
dbCommand.Dispose();
dbCommand = null;
}
#region Get DataSet
public DataSet GetDataSet(string sqlString)
{
DataSet ds = new DataSet();
try
{
MySqlDataAdapter da = new MySqlDataAdapter(sqlString, dbConnection);
da.Fill(ds);
}
catch (Exception ee)
{
throw new Exception("SQL:" + sqlString + "\n" + ee.Message.ToString());
}
return ds;
}
#endregion
//读取数据函数
void ReaderData()
{
//IOS PC IMEI
NetworkInterface[] n = NetworkInterface.GetAllNetworkInterfaces();
userimei = n [0].GetPhysicalAddress().ToString();
//end
userimei_android=SystemInfo.deviceName;
userimei_android2 = SystemInfo.deviceUniqueIdentifier;
MySqlCommand mySqlCommand = new MySqlCommand ("Select * from userdata where uid='"+userimei+"' or uid2='"+userimei_android+"' or uid3='"+userimei_android2+"';", dbConnection);
//MySqlCommand mySqlCommand = new MySqlCommand ("Select * from userdata where uid='Daventh' or uid2='"+userimei_android+"';", dbConnection);
MySqlDataReader reader = mySqlCommand.ExecuteReader ();
if (reader.Read()) {
print ("ID:" + reader.GetInt32 (0) + "--IMEI:" + reader.GetString (1) + "--CID:" + reader.GetString (2));
gameObject.SetActive (false);
//gameObject.SetActive (true);
print (userimei + "||||" + userimei_android+"|||||"+userimei_android2);
//Time.timeScale=0;
} else {
gameObject.SetActive (true);
//gameObject.SetActive (false);
print ("mac-----"+userimei);
print ("macandroid-----"+userimei_android);
}
reader.Close();
}
}