Sending and Receiving data using your own SQL Server - PHP file and TestProject included

11011121315

Comments

  • Shenanigans StudioShenanigans Studio Member, PRO Posts: 73

    @Manto I got it working now! I needed to put .php?username='Jake' instead of .php?username=Jake. Thanks for all your help and patience, you're the best man!

  • MantoManto Member Posts: 796
    edited January 2017

    @Shenanigans Studio said:
    @Manto I got it working now! I needed to put .php?username='Jake' instead of .php?username=Jake. Thanks for all your help and patience, you're the best man!

    Great! You're welcome!

    However, you shouldn't do that in the url, but in the SQL query. So
    $query = mysql_query("SELECT 1 FROM ".$tableName." WHERE username = '".$_GET["username"]."'");

  • Shenanigans StudioShenanigans Studio Member, PRO Posts: 73

    @Manto Thanks for the tip, updated the code and that works too!

  • JScottJScott Member Posts: 143

    Seeing this is the most exciting thing that's ever happened to me:

    So, I got it working, though it's 4 days of my life I'll never get back! The silver lining is that I now have a rudimentary grasp of PHP and SQL.

    Thanks @jonmulcahy for pioneering this and thanks @Manto for the incredible help!

    Aside from a few tweaks, this turned out to indeed be a server issue. It was tricky though because it sorta worked sometimes, enough for me to continue trying to perfect the code (which was beating a dead horse.)

    So, ifast.net works as a host server for this, and their customer service was quite helpful in the end.

    If you are experience problems talk to your hostserver. This is what I got from them:
    "mod security in your cPanel was blocking the request"

    Hopefully it will save you time

  • MantoManto Member Posts: 796

    @Shenanigans Studio said:
    @Manto Thanks for the tip, updated the code and that works too!

    If you haven't done the json returning part yet, here's the PHP code for that:

    // start GET data
    if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    
        // initialize the JSON body variable
        $jsonBody="";
    
        // get table contents
        $query = mysql_query("SELECT 1 FROM ".$tableName." WHERE username = '".$_GET["username"]."' LIMIT 1");
        // construct an array to hold the data we pull from mySQL
        $value = mysql_fetch_row($query);
    
        echo('{"Properties":[],"Name":"","Children":[{"Properties":[{"Name":"rowCount","Value":1},{"Name":"columnCount","Value":1},{"Name":"0-1-name","Value":""},{"Name":"0-1-type","Value":4}],"Name":"id262221_headers","Children":[]},{"Properties":[{"Name":"1","Value":"|' .
            (!($value) ? "1" : "0") .
            '|"}],"Name":"id262221","Children":[]}]}');
    
    } // end of get
    

    So it returns a 1x1 table that contains a single boolean value telling whether the username is available or not.

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408

    @JScott said:
    Seeing this is the most exciting thing that's ever happened to me:

    So, I got it working, though it's 4 days of my life I'll never get back! The silver lining is that I now have a rudimentary grasp of PHP and SQL.

    Thanks @jonmulcahy for pioneering this and thanks @Manto for the incredible help!

    Aside from a few tweaks, this turned out to indeed be a server issue. It was tricky though because it sorta worked sometimes, enough for me to continue trying to perfect the code (which was beating a dead horse.)

    So, ifast.net works as a host server for this, and their customer service was quite helpful in the end.

    If you are experience problems talk to your hostserver. This is what I got from them:
    "mod security in your cPanel was blocking the request"

    Hopefully it will save you time

    fantastic!! glad you got it working

  • gingagaminggingagaming FREELANCE GS DEV Member Posts: 1,685

    @jonmulcahy please check ur PMs

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408

    @gingagaming said:
    @jonmulcahy please check ur PMs

    Thanks for the heads up, I rarely check them. I'll email you this weekend.

  • chaosmasterrochaosmasterro Member, PRO Posts: 51

    Question, has anyone been successful when it comes to using the UPDATE commmand in sql and updating multiple rows at once?

  • MantoManto Member Posts: 796

    @chaosmasterro said:
    Question, has anyone been successful when it comes to using the UPDATE commmand in sql and updating multiple rows at once?

    Well, I haven't used it with GS, but with similar server side code yes. What are you trying to do?

  • chaosmasterrochaosmasterro Member, PRO Posts: 51
    edited January 2017

    @Manto said:

    Well, I haven't used it with GS, but with similar server side code yes. What are you trying to do?

    I was working on leaderboards and I wanted to update everyone's information when a new high score hit the table. But luckily I did find out how to do it. cheers
    Though I did mine a bit different by using ORDER BY and INSERT INTO to compare my scores and DELETE any extra rows with that player's ID.
    But thank you!

    This is completely unrelated, but I ran into a problem that occurs when downloading huge tables off my server. When I try this my game to freezes until the table is fully downloaded. My solution to that is to only retrieve a 10-15 rows and not a couple hundred thousand unnecessary rows.
    Is there even a way to get a specific row based on a specific attribute in Gamesalad? For example I have 10,000 players, each with their own row in my server. But I only need Player X's row data.

  • MantoManto Member Posts: 796

    @chaosmasterro said:
    Is there even a way to get a specific row based on a specific attribute in Gamesalad? For example I have 10,000 players, each with their own row in my server. But I only need Player X's row data.

    Yes, you can put parameters to the get table url. See my previous comments. If you don't have usernames, you can use playerID.

  • chaosmasterrochaosmasterro Member, PRO Posts: 51

    @Manto said:

    Why not let the database check if the username is unique? Send the username using the get table behavior and let the server only return whether the username is available or not. You should be able to send data to server in get table behavior if you add the username to the url, for example like this:

    http://someserver.com/checkusername.php?username=manto

    Then in the php file use $_GET["username"] to access username and a sql query to check if it's unique.

    Found it! Now, I can pull a specific row of data with this. Excellent! Someone else may come along and may need this too.

  • loyaltyappsloyaltyapps Member Posts: 29

    I'm trying to get this working for an HTML5 project. Does anybody know if it should work? It works fine for me in the GS Preview and Android app but nothing happens with the HTML5 version. @jonmulcahy @chaosmasterro @Manto @gingagaming @JScott @Shenanigans Studio

  • chaosmasterrochaosmasterro Member, PRO Posts: 51

    @loyaltyapps said:
    I'm trying to get this working for an HTML5 project. Does anybody know if it should work? It works fine for me in the GS Preview and Android app but nothing happens with the HTML5 version. @jonmulcahy @chaosmasterro @Manto @gingagaming @JScott @Shenanigans Studio

    I don't think it works for HTML5. I have a fully functioning project that use network features but it is unable to access the network for html5. I am on my local server mind you.

  • loyaltyappsloyaltyapps Member Posts: 29
  • loyaltyappsloyaltyapps Member Posts: 29

    In my HTML5 version, GET works perfectly but SEND doesn't send anything, despite displaying a 1 for the Callback Attribute. SEND works fine on all other platforms. Enabled CORS on my server. Any ideas?

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408

    @loyaltyapps said:
    In my HTML5 version, GET works perfectly but SEND doesn't send anything, despite displaying a 1 for the Callback Attribute. SEND works fine on all other platforms. Enabled CORS on my server. Any ideas?

    Where is your server? Is it hosted somewhere? Some hosts just don't work

  • loyaltyappsloyaltyapps Member Posts: 29

    Ah ok. Actually using GoDaddy since I already have several hosting accounts with them. Think that might be the problem? Last year I tried a few of the others mentioned in the forums but they were more confusing. Thanks

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408

    @loyaltyapps said:
    Ah ok. Actually using GoDaddy since I already have several hosting accounts with them. Think that might be the problem? Last year I tried a few of the others mentioned in the forums but they were more confusing. Thanks

    Yes I think people have reported problems with godaddy before. I use site5, always worked

  • loyaltyappsloyaltyapps Member Posts: 29

    I'll try that, thanks for your help!

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408

    @loyaltyapps said:
    I'll try that, thanks for your help!

    No prob. Good luck! It's always exciting when it comes together

  • loyaltyappsloyaltyapps Member Posts: 29

    I actually noticed this in the Error Log, not sure whether it's the problem or just a warning for future:

    PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in ........... /send.php on line 7

  • loyaltyappsloyaltyapps Member Posts: 29

    Tried site5. Same problem. SEND not sending anything to the db on the html5 version, despite seeing a 1 for Callback. GET works fine. SEND & GET all good in the Preview and on Android, but no use to me. Any ideas?

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408

    enable some of the logging I commented out to make sure your server is receiving the json package, it should just dump it to a txt file. also check the server logs are not showing any permissions / missing file errors

  • loyaltyappsloyaltyapps Member Posts: 29

    The json.txt and updatedjson.txt files are in the folder, the former is empty, the latter only shows the data from my tests in the GameSalad previewer. It does not display any of the info submitted in the HTML5 version.

    Not sure what this means: "enable some of the logging I commented out"

    Not seeing any permissions / missing file errors

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408

    I'm not 100% send/receive works in html5 versions. it's been awhile

  • loyaltyappsloyaltyapps Member Posts: 29

    Ok, receiving the data works seamlessly. 644 permissions for send.php etc?

  • StormyStudioStormyStudio United KingdomMember Posts: 3,989

    I love that this thread is active a good few years later.... I hope everyone at GS is good.... Hi @jonmulcahy ... From Stormy...

  • loyaltyappsloyaltyapps Member Posts: 29

    Update: the json.txt is always empty in my File Manager when sent from the HTML5 version. Whereas it contains the correct info when sent from the Preview and Android version. Send.php code attached. Any ideas?

Sign In or Register to comment.