Unity連接MySQL并讀取表格數(shù)據(jù)的實現(xiàn)代碼
發(fā)布日期:2022-02-10 16:32 | 文章來源:源碼之家
表格如下:

在Unity讀取并調(diào)用時的代碼:


而如果想要查看該數(shù)據(jù)庫中的另一個表,不是直接使用Table[1],而是需要更改SELECT * from <?>的表名


代碼:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MySql.Data.MySqlClient;
using System.Data;
using System;
public class getGameUserAccount : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
mySqlCon();
}
// Update is called once per frame
void Update()
{
}
public void mySqlCon()
{
//數(shù)據(jù)庫登錄數(shù)據(jù)
string conStr = "server=localhost;User Id = root;password=123456;Database=gamerdata;charset=utf8";
//建立連接
//實例化的同時調(diào)用MySqlConnection,傳入?yún)?shù)
//這里的傳入?yún)?shù)個人認為是CMD里面的直接輸入了,string格式直接類似手敲到cmd里面
MySqlConnection myCon = new MySqlConnection(conStr);
//打開連接
myCon.Open();
//插入數(shù)據(jù),其中useraccount為表名,括號內(nèi)為表的格式
/*
//此處注釋是因為不能添加相同主鍵的值
MySqlCommand myCmd = new MySqlCommand("insert into useraccount(id,nickname,password) values (4,'list','testList')", myCon);
if (myCmd.ExecuteNonQuery() > 0)
{
Debug.Log("Query Success!");
}
*/
//查詢數(shù)據(jù)
string selStr = "select * from useraccou
到此這篇關(guān)于Unity連接MySQL時讀取表格的方式的文章就介紹到這了,更多相關(guān)Unity連接MySQL讀取表格內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
相關(guān)文章
關(guān)注官方微信