当前位置:网站首页>Unity connects to the database

Unity connects to the database

2022-07-05 04:52:00 yaohuiyaoo

1. First, in the Assets So let's create one Plugins Folder
2. stay Plugins Put... Under the folder Mysql.Data.dll,System.Data.dll,System.Drawing.dll below
3. newly build C# Code file
open C# file , introduce using Mysql.Data.MysqlClient
Create connection objects
string s=“server=localhost;database=student;userid=root;password=root;”
MysqlConnection con=new MysqlConnection(s);
con.open();
string sql=“insert into xinxi value(“ Rage ”,888)”;
MysqlCommand msc=new MysqlCommand(sql,con);
if(msc.ExecuteNorQuery()>0){

print(“ Successful operation ”);
}
else{
print(“ operation failed ”);
}
MysqlDataReader reader=msc.ExecutReader();
while(reader.Read()){
int id=reader.GetInt(“id”);
string name=reader.GetString(“name”);
print(id+"\t"+name);
}
reader.close();
con.close();
2.count(*) Return the number of all records in the table , It is equivalent to counting all rows
count(1) Return the number of rows that are not empty
count( Name ) Returns the number of rows in the specified column , Does not contain empty records
3. Multi-table query
Internal connection :select surface . Field , surface . Field from Table name inner join Table name on Foreign keys = Primary key
Left connection :select Table name . Field , Table name . Field from Table name inner join Table name on Foreign keys = Primary key
4. Aggregate functions
count() How many lines
max() For maximum
min() For the minimum
avg() averaging
sum() Sum up
group by grouping
order by desc Descending

原网站

版权声明
本文为[yaohuiyaoo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140626299170.html