- Home /
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.
][1]
Best regards,
Andreas.
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.
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.
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?
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)
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?
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.
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.
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.
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
![](https://koobas.hobune.stream/wayback/20220613161515im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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