Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling php script using C# (Unity)

    I'm fairly new to both Unity and PHP, and I am currently working on a project where I can parse data from a MySQL database to Unity, using PHP.

    I initially wanted to try and enable a method where the user can perhaps change the php script and enable it to choose a different table of data, however I was advised that it may be safer to list all variables within the php script and call it from Unity accordingly;

    Display.php
    Code:
    $table = mysql_real_escape_string($_GET['table'], $db);
    
    if ($table == "shoes") { 
    $query = "SELECT * FROM `shoes` ORDER by `price` ASC LIMIT 10";
    
    elseif ($table == "sneakers") { 
    $query = "SELECT * FROM `sneakers` ORDER by `price` ASC LIMIT 10";
    
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    $num_results = mysql_num_rows($result);  
    
    for($i = 0; $i < $num_results; $i++)
      {
           $row = mysql_fetch_array($result);
           echo $row['shopname'] . "\t" . $row['price'] . "\n";
      }
    ?>
    I'm having trouble calling the php and choosing the table that I want to select, I am pretty new to this, so I apologise if this seems completely incompetent to you guys.

    Here is the my Unity Script;

    HSController.cs

    Code:
    void Start()
    {
        StartCoroutine(GetScores());
    }
    
    // remember to use StartCoroutine when calling this function!
    IEnumerator PostScores(string name, int score)
    {
    
    
        string hash = Md5Sum(name + score + secretKey);
    
        string post_url = addScoreURL + "name=" + WWW.EscapeURL(name) + "&score=" + score +   "&hash=" + hash;
    
        WWW hs_post = new WWW(post_url);
        yield return hs_post; // Wait until the download is done
    
        if (hs_post.error != null)
        {
            print("There was an error posting the high score: " + hs_post.error);
        }
    }
    
    
    IEnumerator GetScores()
    {
        gameObject.guiText.text = "Loading...";
        WWW hs_get = new WWW(highscoreURL);
        yield return hs_get;
    
        if (hs_get.error != null)
        {
            print("There was an error getting the high score: " + hs_get.error);
        }
        else
        {
            gameObject.guiText.text = hs_get.text; // this is a GUIText that will display the scores in game.
            }
        }
    
    }
    Any help or a point in the right direction would be great!

    Kind Regards

  • #2
    New Coder
    Join Date
    Dec 2014
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling php script using C#

    im running a PowerShellScript as a Custom Action. In my script i want to have "placeholders" or parameters, so when i call the .msi via comandline i can parse in these values for the parameters.
    How can i do that?

    Thanks
    Geron


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •