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
1
Question by AndreasX12 · Aug 25, 2014 at 04:27 PM · c#databasereadtable

Acces phpMyAdmin table from C#

Hello,

I'm developing a mobile application for Android and iOS. I'm trying to figure out how to acces my phpMyAdmin table from the internet. (I have it hosted on my webpage).

As you can see in the picture below, there are 50,000 adresses (It is a very big database.) and they each have a value with price and a link I need those adresses to show on a list (and then a map). How will this be possible? I have no experience in PHP.

![alt text][1]

Best regards,

Andreas.

table.png (91.5 kB)
table.png (91.5 kB)
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

2 Replies

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

Answer by code_warrior · Aug 25, 2014 at 06:23 PM

phpMyAdmin is just the a userfriendly backend for a database like MySQL-database. What you now need is a PHP Script that runs and SQL statement similar to "SELECT Price, Link From ". You can then call the PHP script from the WWW class, then you can use the returned informations (WWW.text) to display them in a map. I've recently worked on a tutorial series about creating a secure scoreboard system with a mysql database to insert and querry data from the database, I think this one might also be useful for your case.

Comment
Add comment · Show 6 · 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 AndreasX12 · Aug 25, 2014 at 06:32 PM 0
Share

Thanks for your answer.

Are your tutorials available for public yet? I'm actually looking for some tutorials help me with the coding, because I have never worked with PHP before - although I have a lot of experience in C#. If I could acces the information from Unity, I would have no problems with the following coding.

Best regards, Andreas.

avatar image AndreasX12 · Aug 25, 2014 at 07:29 PM 0
Share

Okay so I figured out how to show the $$anonymous$$ySQL table as a HT$$anonymous$$L table.

You can see it here: http://danico.dk/acces_data.php

Somehow I can't get Unity to 'read' the table accordingly.

This is my code:

 void Start () {
 
     string data = GetData("http://danico.dk/acces_data.php").ToString ();
     guiText.text = data;
     
 }
 
 WWW www;
 
 IEnumerator GetData(string URL) {
 
     www = new WWW(URL);
     yield return www.text;
     
 }


What am I doing wrong?

avatar image code_warrior · Aug 25, 2014 at 07:30 PM 0
Share

Hi Andreas, I am sorry but the tutorial is not yet public, but it will be published within a few days. When it is available I will drop a link.

An easy PHP-Example for displaying your two appropriate columns. The script will return the price and link of all the entrys.

 <?php
     $hostname = 'localhost';
     $username = '<your-username>';
     $password = '<your-password>';
     $database = '<your-database-name>';
 
     $con = mysqli_connect($hostname, $username, $password, $database);
 
     if(mysqli_connect_errno()){
 
         echo "Failed to connect " . mysqli_connect_errno();
     }
 
     $result = mysqli_query($con, "Select pris,link FRO$$anonymous$$ <name_of_your_table>");
 
 
     while ($row = mysqli_fetch_array($result)) {
         echo $row['pris'] ." ".$row['link'] . PHP_EOL;
 
     }
     mysqli_close($con);
 ?>


If you want to enhance the security of your php script You could create an encrypted file that stores the credentials, and put the PHP Script (above) in a different directory (outside of the html directory)

avatar image AndreasX12 · Aug 26, 2014 at 06:11 AM 0
Share

Thank you for your code. I figured out how to show the $$anonymous$$ySQL table as a HT$$anonymous$$L table.

You can see it here: http://danico.dk/acces_data.php

Somehow I can't get Unity to 'read' the table accordingly.

This is my code:

void Start () {

 string data = GetData("http://danico.dk/acces_data.php").ToString ();
 guiText.text = data;
 

}

WWW www;

IEnumerator GetData(string URL) {

 www = new WWW(URL);
 yield return www.text;
 

} What am I doing wrong?

avatar image code_warrior · Aug 26, 2014 at 03:33 PM 0
Share

Hi Andreas,

this is an working example about fetching data from a webserver in C#:

 using UnityEngine;
 using System.Collections;
 public class WWWScript : $$anonymous$$onoBehaviour {
 
     Vector2 position;
     private Rect windowRect = new Rect(0, 0, Screen.width, Screen.height);
     string answer;
     string url = "www.alexbilz.com/Unity/Display.php";
 
 
     void Start () {
 
         WWW get_www = new WWW(url);
         //Start the Coroutine
         StartCoroutine(WaitForRequest(get_www));
     }
     //Our Coroutine for getting the data
     IEnumerator WaitForRequest(WWW www)
     {
         yield return www;
         
         // check for errors
         if (www.error == null)
         {
 
             //Assign the data that was fetched to the variable answer
             answer = www.text.ToString();
         } else {
             Debug.Log("WWW Error: "+ www.error);
         }    
     }
 
     //GUI Components
 
     void OnGUI() {
         windowRect = GUI.Window(0, windowRect, Do$$anonymous$$yWindow, "$$anonymous$$y Window");
     }
     void Do$$anonymous$$yWindow(int windowID) {
         position = GUILayout.BeginScrollView(position);
         GUILayout.Label(answer);
         GUILayout.EndScrollView();    
     }
 }

The only problem is that you need to change your PHP-Script a bit, as the WWW-Class is not able display HT$$anonymous$$L-Tags (Like table, th, tr..) properly. Ins$$anonymous$$d you could return the raw data (as a text) and then check the www.data row by row in Unity.

Show more comments
avatar image
0

Answer by FlaSh-G · Aug 25, 2014 at 05:06 PM

There is no such thing like a phpMyAdmin table. I guess you have a MySQL table. Build a backend (with php, for example) and access its service via WWW class.

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 AndreasX12 · Aug 25, 2014 at 05:22 PM 0
Share

Yes, sorry - I mean a $$anonymous$$ySQL table (It's just the screenshot that is from php$$anonymous$$yAd$$anonymous$$).

I have no experience in PHP, so do you know any tutorials or documentation on how I can do that? I suppose it's something like uploading a PHP script on my website, and then acces it using WWW (as you also say).

Thank you.

avatar image FlaSh-G · Aug 25, 2014 at 07:28 PM 0
Share

Sounds about right. There are lots of tutorials for both topics. There are also a lot of bad ones. php is taught badly by many people, so prepare to relearn some things concerning php later on :)

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

24 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Display the data in the form of table 2 Answers

Why is get_url adding an extra 'http://'? -- DB request fail 1 Answer

How to connect my Application to SQLite Database? 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