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 MichaelTaylor3d · Aug 15, 2012 at 06:53 PM · serverdatabasemysqlphp

Accessing a database though $_GET

After reading the following posts I have a few questions: How can I send and receive data to and from a URL, i.e. server side scripts, web services, etc?

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

I guess this is more of a PHP question so I still hope it applies here.

I was wondering if anyone knew of any examples of a php server side script that can accept unity GET request, extract out the parameters and then inset those parameters into a function (this function I will use to query my database)

From what I understand from the UNITY side, I can pass the URL + Parameters through the WWW class to initiate the GET request.

 var url = "http://example.com/script.php?var1=value1&var2=value2";
 WWW www = new WWW(url);
 ///And So on

So the question is how i set up my PHP script to be able to do something with this request.

I think I can start out with the following in my php script

 <?php

  if (isset($_GET['url'])) 
  {
     $url = $_GET['url'];
  }

 ?>

Am I understanding this correctly that this will set $url to http://example.com/script.php?var1=value2&var2=value2 ?

If this is correct I should then be able to parse out my parameters into an array that I can feed into my query function. Using a series of string manipulators.

Once I have this array I should be able to feed them into my function:

  <?php

 function Query(value1, value2)
 {
    //do some awesome Query stuff
    return result;
 }
 ?>

Assuming I have everything right up until now, this is where I get stuck, How to I take the result of my function so that it get sent back to the www result of my unity script?

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

1 Reply

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

Answer by DaveA · Aug 15, 2012 at 06:55 PM

For your example:

 var url = "http://example.com/script.php?var1=value1&var2=value2";
 WWW www = new WWW(url);

Script might be:

 <?php
 
  if (isset($_GET['var1'])) 
     $var1 = $_GET['var1'];
  if (isset($_GET['var2'])) 
     $var2 = $_GET['var2'];
  echo ("got $var1 and $var2");
 ?>

and your www object will get it in .text like

   var result = www.text; // result should now be 'got value1 and value2'
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 MichaelTaylor3d · Aug 15, 2012 at 08:15 PM 0
Share

so the www.text will be whatever I echo to the page?

So after your code I can do something like

 function Query($var1)
 {
     //do some stuff to find query result
       echo Query result
 }

and then www.text will contain the query result?

avatar image DaveA · Aug 15, 2012 at 09:03 PM 0
Share

Yes. And if you are returning stuff formatted as X$$anonymous$$L you can send that into an X$$anonymous$$LDocument and it will parse that for you.

avatar image MichaelTaylor3d · Aug 15, 2012 at 09:08 PM 0
Share

Works! and it was much easier then I thought, Thanks!

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Database and Unity 0 Answers

Why i keep getting this message : Wrong response ? 0 Answers

mystery MYSQL error .. 2 Answers

Upload an image onto the database from Unity 1 Answer

www php send data to mysql 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