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
2
Question by DanjelRicci · May 26, 2010 at 08:30 AM · webconnectionmysqlphpwebpage

Is it possible to send and recieve data from/to a MySql server?

Hi everyone! I want to create a PHP website with a MySql server, where users can register, login, and then get "coins" (like an arcade game). Then users can use those "coins" to play 3D webgames made with Unity.

Can I get the Unity webgames communicate with the MySql server, in order to send and retrieve data like username, login, number of available coins, etc?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by duck · May 26, 2010 at 01:27 PM

You should use standard HTTP Get or Post requests, via Unity's WWW class, to send requests to your PHP scripts, and read the responses.

The PHP scripts on your server would then communicate with the Database, and perform tasks like checking whether a username is available, creating new accounts, logging in, retrieving account data, etc.

You should consider it in a similar way to how you would build it as if it had a simple web page based form interface, but instead of typing in the form values into text boxes, you pass them as values via scripts. The returned page can then contain the data in whatever format you want, for your game to process.

For more information, see this Question:
How can I send and receive data to and from a URL, i.e. server side scripts, web services, etc?

Comment
Add comment · Show 2 · Share
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
avatar image DanjelRicci · May 26, 2010 at 05:05 PM 0
Share

Thank you very much, this sounds really helpful and easy too. ;)

avatar image fadilRaditya · Aug 27, 2012 at 02:20 PM 1
Share

the site is dead.. can someone help me again?

avatar image
-1

Answer by Tobias · May 26, 2010 at 08:43 AM

Yes you can with cs

Just use mysql connector for cs and import the MySql.Data.dll to your project.

Here is an example mysql connect script:

using UnityEngine; using System.Collections; using MySql.Data.MySqlClient; using System;

public class mysqlconn : MonoBehaviour { static string row =""; // Use this for initialization public string Start () {

 string myConnectionString = "SERVER=localhost;" +
                         "DATABASE=yugioh;" +
                         "UID=root2;";
     MySqlConnection connection = new MySqlConnection(myConnectionString);
     MySqlCommand command = connection.CreateCommand();
     command.CommandText = "SELECT * FROM accounts";
     MySqlDataReader Reader;
     try {
     connection.Open(); 
     Reader = command.ExecuteReader();


while (Reader.Read()) { for (int i = 0; i < Reader.FieldCount; i++) row += Reader.GetValue(i).ToString() + ", "; } }

     catch (Exception x) {
         Debug.Log(x.Message);
         return x.Message;
     }

connection.Close(); return row;

 }

 // Update is called once per frame
 void Update () {

 }

}

Comment
Add comment · Show 3 · Share
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
avatar image duck ♦♦ · May 26, 2010 at 01:22 PM 2
Share

No no no! This would create a huge security hole! In the scenario that $$anonymous$$r. Drayton describes, you should never allow the client on the end user's machine to directly connect to your DB! (see my answer)

avatar image ikriz · Jun 15, 2010 at 02:50 PM 0
Share

plus in a webplayer you cant use .dll files...

avatar image murthyveera · Sep 18, 2012 at 12:05 PM 0
Share

hi, Tobias Windberg can u please send me the exact procedure or code to make sure run properly without any loop holes

avatar image
0

Answer by Jack Wong · Feb 19, 2014 at 03:43 AM

This one perhaps? http://answers.unity3d.com/questions/11021/how-can-i-send-and-receive-data-to-and-from-a-url.html I'm also currently searching way to do this, update me if you found the solution :)

Comment
Add comment · Share
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
avatar image
0

Answer by tsondhi2006 · Sep 26, 2018 at 06:33 AM

I couldn't do it directly from unity but managed to do it using MySQL, PHP and of course C# in unity

I have posted the answer in another thread if you would want to see it

https://forum.unity.com/threads/reading-database-and-or-spreadsheets.11466/#post-3720700

Comment
Add comment · Share
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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Web Player and database 1 Answer

MySql On Web ? 1 Answer

Best way (performance) to connect to a (MYSQL) DB 2 Answers

Unity Null Reference Error 1 Answer

My code to php -> sql in PC good, in Android not work. plese fast 1 Answer


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