Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by missypooh · Mar 19, 2012 at 03:17 AM · databasemysql

mySQL : Values not inserting to my database

Hi, i am using mySQL. The code snippet below is what i have coded to make sure that the data are stored into the database. In the console, i get this "insert values into database. But it is not updating my datbases. Anyone know what wrong?? And i feel quite weird regarding the way i insert the value of monitorID and playerID. For monitorID, it is auto increment, so i am suspecting that it is the correct way to put 1. Another thing is the playerID, i don't know how am i going to get the iD? hmm

I understand we need to prevent cheating from client, which mean that the server will be responsible for updating the database. So for my case, my client will update the database. This is an for monitoring purpose. So i just want to record what the player have click. It is fine if i do it this way? Or i have to inform the server (using builtin master server) and ask the server to do the updating? Any advice or sugggestion?

Thank you for spending time to read. :)

 /***************** connect database, initialization **************/
 // MySQL instance specific items
 var constr = "Server=localhost;Database=games;UserID=chinese;Password=chinesegames;Pooling=true";
 // connection object
 var con;
 // command object
 var cmd;
 // reader object
 var rdr;
 // object collection array
 var bodies                                        : GameObject[];
 var saving                                         = false;
 var loading                                     = false;
 // collection container
 var _GameItems;
 
 // values to match the database columns
 var monitorID;
 var playerID;
 var radical00;
 var radical0;
 var fullWord;
 var wrong = " ";
 var teacherComment = " ";
 
 /********************** end of connection to database **********************/
 /********************** saving data into monitor table *************************/
     saving = true;
                 
 var query;
 var levelname    = Application.loadedLevelName;
 var radical00     = selected_00.GetComponent(textOnMouse00).thisRadical.Ctext;
 var radical0     = selected_0.GetComponent(textOnMouse0).thisRadical.Ctext;
 var fullWord     = selected_0.GetComponent(textOnMouse0).thisRadical.form;
 var teacherComment = " ";
                 
 if(isWrong)
     wrong = "True";
 else
     wrong = "False";

      // Error trapping in the simplest form
 try
 {
 query = "INSERT INTO monitor(monitorID, playerID, gameLevel,radical00, radical0,fullWord, wrong, teacherComment) VALUES (1,1, ?gameLevel,?radical00, ?radical0, ?fullWord, ?wrong, ?teacherComment)";

          if (con.State.ToString() != "Open")
      {
     con.Open();
 var cmd = new MySql.Data.MySqlClient.MySqlCommand(query, con);
 //var oParam = cmd.Parameters.AddWithValue("?monitorID", monitorID);
 //var oParam1 = cmd.Parameters.AddWithValue("?playerID", playerID);
 var oParam2 = cmd.Parameters.AddWithValue("?gameLevel", levelname);
 var oParam3 = cmd.Parameters.AddWithValue("?radical00", radical00);
 var oParam4 = cmd.Parameters.AddWithValue("?radical0", radical0);
 var oParam5 = cmd.Parameters.AddWithValue("?fullWord", radical00);
 var oParam6 = cmd.Parameters.AddWithValue("?wrong", wrong);
 var oParam7 = cmd.Parameters.AddWithValue("?teacherComment", teacherComment);
 cmd.ExecuteNonQuery();
 print("insert values into database");
                 
 }
                         
 }
 catch (ex)
 {
      Debug.Log(ex.ToString());
 }
                 
 // you could also use the update if you know the ID of the item already saved
     saving = false;
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Setup mySQL, insert value to mySQL, retrieve data from mySQL 0 Answers

Finish setup php, how to communicate with mySQL and unity 2 Answers

c# database connection on debian server 0 Answers

How to use php to update mySQL 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges