The table is as follows: Code when Unity reads and calls: If you want to view another table in the database, instead of using Table[1] directly, you need to change the table name in Code: 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() { //Database login data string conStr = "server=localhost;User Id = root;password=123456;Database=gamerdata;charset=utf8"; //Establish connection //Call MySqlConnection while instantiating, pass in parameters //I personally think the parameters here are directly input in CMD, the string format is directly similar to typing it into cmd MySqlConnection myCon = new MySqlConnection(conStr); //Open the connection myCon.Open(); //Insert data, where useraccount is the table name and the table format is in brackets/* //The comment here is because you cannot add values with the same primary key MySqlCommand myCmd = new MySqlCommand("insert into useraccount(id,nickname,password) values (4,'list','testList')", myCon); if (myCmd.ExecuteNonQuery() > 0) { Debug.Log("Query Success!"); } */ //Query data string selStr = "select * from useraccount"; MySqlCommand mySelect = new MySqlCommand(selStr, myCon); DataSet ds = new DataSet(); try { MySqlDataAdapter da = new MySqlDataAdapter(selStr, myCon); da.Fill(ds); Debug.Log(ds.Tables[0].Rows[0][0]); Debug.Log(ds.Tables[0].Rows[0][1]); Debug.Log(ds.Tables[0].Rows[0][2]); Debug.Log(ds.Tables[0].Rows[0][3]); //Table[0].Rows[0][0] Debug.Log("Query Success!"); } catch (Exception e) { throw new Exception("SQL:" + selStr + "\n" + e.Message.ToString()); } myCon.Close(); } } This is the end of this article about how to read tables when Unity connects to MySQL. For more information about how to read table content when Unity connects to MySQL, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of the sticky position attribute in CSS
>>: 12 Javascript table controls (DataGrid) are sorted out
The effect of completing a menu bar through displ...
During the crawler development process, you must ...
Preface This article explains how to create a dat...
1. Overview Users expect the web applications the...
Table of contents Loop - for Basic use of for loo...
Table of contents Preface 1. MySQL enables SSL co...
Add monitoring host Host 192.168.179.104 is added...
There are many database management tools for MySQ...
1. ROW_NUMBER() Definition: The ROW_NUMBER() func...
1. Dynamically loading scripts As the demand for ...
1.1. Download: Download the zip package from the ...
Docker queries or obtains images in a private reg...
Table of contents Problem description: Cause Anal...
Table of contents 1. redo log (transaction log of...
This article attempts to write a demo to simulate...