客户端主机,安装Unity,在Unity中编写一个客户端功能。连接服务器端MySql数据表并提取数据的代码如下:
public void ReceiveDataFromMysql()
{
string constructorStr = "server=‘192.168.1.112’; uid=‘root’; pwd=‘root’; database=‘sys’; "; //server IP地址及其他参数根据自己的情况更改
sqlconn = new MySqlConnection(constructorStr);
sqlconn.Open();
Debug.Log(sqlconn.State);
string cmdText = "select * from sys_config where value=100";
cmd = new MySqlCommand(cmdText, sqlconn);
MySqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
value = reader.GetString("variable");
}
Debug.Log(value);
text.text = value;
sqlconn.Close();
}