What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » MySQL

Pages: (2): « First [ 1 ] 2 » Last »
MySQL
Author: Message:
ArkaneArkade
Full Member
***

Avatar
The One and Only

Posts: 193
Reputation: 5
39 / Male / Flag
Joined: Mar 2007
O.P. MySQL
Hey guys,

I know this isn't really the point of the forum, but I figure it's still script related, so hopefully be ok.
I'm looking for suggestions or recommendations on how to improve my script to get data from a MySQL database.
I've looked over the forums already, and know there no way for plus to do it directly (at least no simple way), but I figured there still may be a much more efficient way than I currently have set up.

At the moment, data is added to MySQL via php pages, which then read the entire database into an xml file, which is accessed by my script.  At the moment however, this takes a good 10 seconds on my connection, and over a minute on a friends, which isnt really a great time especially with the database growing, so I need an alternative.

My best thought at the moment (best meaning hopefully will work but I dont really have a clue) is to make xml a file extension that is handled by php, and use $_POST or $_GET for the search term, but I cant do this currently (changing server tomorrow to hopefully get the ability).

I just thought I'd throw my hat in, see if anyone can suggest anything better for the system.

Cheers
Leroux
[Image: adsig.jpg]
04-26-2009 10:34 PM
Profile E-Mail PM Web Find Quote Report
MeEtc
Patchou's look-alike
*****

Avatar
In the Shadow Gallery once again

Posts: 2200
Reputation: 60
38 / Male / Flag
Joined: Nov 2004
Status: Away
RE: MySQL
I would support the POST o GET method, and depending on the amount of dta being sent, a JSON object might be a bit better.
[Image: signature/]     [Image: sharing.png]
I cannot hear you. There is a banana in my ear.
04-27-2009 12:03 AM
Profile PM Web Find Quote Report
ArkaneArkade
Full Member
***

Avatar
The One and Only

Posts: 193
Reputation: 5
39 / Male / Flag
Joined: Mar 2007
O.P. RE: MySQL
Cheers MeEtc.  I've neevr used JSON before, but it looks like it might be quite good and easy to implement.  Only gonna be downloading 5 different things.
For my limits, will definitly be easier to write a JSON script than an xml one (as far as my tests have shown.

Cheers for the input man.
[Image: adsig.jpg]
04-28-2009 11:57 AM
Profile E-Mail PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: MySQL
JSON is terribly simple. Make a PHP array, output the result of json_encode of your array and eval() it in JScript.

If you want to go one step further, you could steal some functions from a JavaScript framework like PrototypeJS or jQuery to check the received JSON code for any potentially malicious code, such as function calls. However in a case of a simple Plus! script, you probably won't really need such extra security measures.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
04-28-2009 04:25 PM
Profile E-Mail PM Web Find Quote Report
ArkaneArkade
Full Member
***

Avatar
The One and Only

Posts: 193
Reputation: 5
39 / Male / Flag
Joined: Mar 2007
O.P. RE: RE: MySQL
quote:
Originally posted by Matti
JSON is terribly simple. Make a PHP array, output the result of json_encode of your array and eval() it in JScript.

You guys just delight in making me feel bad don't you. :P
One thing though, as I already have my script working with XML (although possibly going to fail soon due to server changes), would it be possible to have multiple things determined by case?

To explain better, I used xml because sometimes I needed data according to case sensitive fields, such as "Sonic the Hedgehog" and "SONIC THE HEDGEHOG" getting different data, and the xml nodes allowed this well.  Would I be able to (easily) set up this in JSON, or gonna need complicated workarounds?

Leroux = The worlds oldest, most experienced scripting newbie.
[Image: adsig.jpg]
04-28-2009 10:45 PM
Profile E-Mail PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: MySQL
quote:
Originally posted by Leroux
..., would it be possible to have multiple things determined by case?
Sure! Both PHP and JScript are case-sensitive when it comes to assigning a key to an array or object.

This allows you to do things like:
php code:
<?php
$test = array(
    "foo" => "bar",
    "FoO" => "cookie"
);
?>
and
js code:
var test = {
    "foo" : "bar",
    "FoO" : "cookie"
};
and both will give you an array/object with 2 values indexed by 2 keys.

This means that you can safely add a key to a PHP array, output it as JSON and retrieve it in JScript without any trouble with possibly similar key names. :)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
04-29-2009 11:06 AM
Profile E-Mail PM Web Find Quote Report
ArkaneArkade
Full Member
***

Avatar
The One and Only

Posts: 193
Reputation: 5
39 / Male / Flag
Joined: Mar 2007
O.P. RE: MySQL
OK guys, I've finally set up the site, to add a json output, using php.
I'm a bit unclear as to how to do it on the msgpus side however.
Do I just download the page as a variable using XMLHTTP or is there another step in it, and then how do I eval() it?

I'm trying to test with http://arkanes-arkade.co.uk/x360/json.php?id=Sonic%20the%20hedgehog because I know sonic changes with the case.  Everything I've read seems to want something such as JSON[0] to define the info.  Would that make this gameid[0], where gameid is either SONIC THE HEDGEHOG or Sonic The Hedgehog?

Sorry to keep bothering.  I am trying to learn, I promise.
[Image: adsig.jpg]
05-02-2009 09:10 PM
Profile E-Mail PM Web Find Quote Report
felipEx
Scripting Contest Winner
***


Posts: 378
Reputation: 24
35 / Male / Flag
Joined: Jun 2006
RE: MySQL
quote:
Originally posted by Leroux
I'm a bit unclear as to how to do it on the msgpus side however.
Do I just download the page as a variable using XMLHTTP or is there another step in it, and then how do I eval() it?

Well, let's take the output from the php snipped posted by Matti

code:
{"foo":"bar","FoO":"cookie"}

Something like this should do the trick

JScript code:
xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
        var results = eval( '(' + xmlhttp.responseText + ')' );
        Debug.Trace(results.foo);
        Debug.Trace(results.FoO);
    }
}


quote:
Originally posted by Leroux

I'm trying to test with http://arkanes-arkade.co.uk/x360/json.php?id=Sonic%20the%20hedgehog because I know sonic changes with the case.  Everything I've read seems to want something such as JSON[0] to define the info.  Would that make this gameid[0], where gameid is either SONIC THE HEDGEHOG or Sonic The Hedgehog?

Unfortunately that website doesn't seem to be loading here... just wondering what do you get as output so we can have a look.
Also, you might want try out this online-JSON-editor and play around with JSON :)
05-03-2009 01:12 AM
Profile E-Mail PM Find Quote Report
ArkaneArkade
Full Member
***

Avatar
The One and Only

Posts: 193
Reputation: 5
39 / Male / Flag
Joined: Mar 2007
O.P. RE: RE: MySQL
quote:
Originally posted by felipEx

Unfortunately that website doesn't seem to be loading here... just wondering what do you get as output so we can have a look.
Also, you might want try out this online-JSON-editor and play around with JSON :)


Cheers felipEx, I'm having a look over that.  I'd gotten pretty similar to what you just showed me, but not working.

Heres what I get from the JSON page.  It's been trimmed, but just by removing a couple fields, so as not to be too cluttered.
code:
SONIC THE HEDGEHOG:{"Title":"Sonic The Hedgehog","PSM":"A blue streak speeds by - It\\'s Sonic The Hedgehog"}
Sonic The Hedgehog:{"Title":"Sonic The Hedgehog","PSM":"Faster than the naked eye - It\\'s Sonic The Hedgehog"}

I'm having trouble with the eval function however.  I kept getting "Error: Expected ';' (code: -2146827284)".  Now that I've changed it to your however, with the extra "(" and ")" in it, I instaed get "Error: Expected ')' (code: -2146827282)".
The exact line used is
code:
var results = eval( "(" + http.responseText + ")" );
(I already had it setup using http as my var, so I figured it was easier to change that than all of mines.. lazy you kniow)

- Out of interest, why are the extra brackets added?  Just so I fully understand the code I use.

This post was edited on 05-03-2009 at 01:35 AM by ArkaneArkade.
[Image: adsig.jpg]
05-03-2009 01:33 AM
Profile E-Mail PM Web Find Quote Report
felipEx
Scripting Contest Winner
***


Posts: 378
Reputation: 24
35 / Male / Flag
Joined: Jun 2006
RE: MySQL
quote:
Originally posted by Leroux
I'm having trouble with the eval function however.  I kept getting "Error: Expected ';' (code: -2146827284)".  Now that I've changed it to your however, with the extra "(" and ")" in it, I instaed get "Error: Expected ')' (code: -2146827282)".

- Out of interest, why are the extra brackets added?  Just so I fully understand the code I use.
That's because the "syntax" of your json object is incorrect so the parser throws an error :D


code:
SONIC THE HEDGEHOG:{"Title":"Sonic The Hedgehog","PSM":"A blue streak speeds by - It\\'s Sonic The Hedgehog"}
Sonic The Hedgehog:{"Title":"Sonic The Hedgehog","PSM":"Faster than the naked eye - It\\'s Sonic The Hedgehog"}


I got a better way to organize this output and deal it with JScript.

code:
{"results": [
        {"Title": "Sonic The Hedgehog", "PSM": "A blue streak speeds by - It\\'s Sonic The Hedgehog"},
        {"Title": "Sonic The Hedgehog", "PSM": "Faster than the naked eye - It\\'s Sonic The Hedgehog"},
        {"Title": "Sonic The Hedgehog", "PSM": "test"}
    ]
}

JScript code:
        xmlhttp.onreadystatechange = function(){
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
                var json = eval( '(' + xmlhttp.responseText + ')' );
               
                for (var x = 0; x < json.results.length; x++){
                    Debug.Trace(json.results[x].Title + "\n" + json.results[x].PSM);
                }
               
            }
        }
05-03-2009 02:57 AM
Profile E-Mail PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On