MySQL - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: MySQL (/showthread.php?tid=90372)
MySQL by ArkaneArkade on 04-26-2009 at 10:34 PM
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
RE: MySQL by MeEtc on 04-27-2009 at 12:03 AM
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.
RE: MySQL by ArkaneArkade on 04-28-2009 at 11:57 AM
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.
RE: MySQL by Matti on 04-28-2009 at 04:25 PM
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.
RE: RE: MySQL by ArkaneArkade on 04-28-2009 at 10:45 PM
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.
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.
RE: MySQL by Matti on 04-29-2009 at 11:06 AM
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.
RE: MySQL by ArkaneArkade on 05-02-2009 at 09:10 PM
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.
RE: MySQL by felipEx on 05-03-2009 at 01:12 AM
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
RE: RE: MySQL by ArkaneArkade on 05-03-2009 at 01:33 AM
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.
RE: MySQL by felipEx on 05-03-2009 at 02:57 AM
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
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);
}
}
}
RE: MySQL by Matti on 05-03-2009 at 07:23 AM
quote: Originally posted by Leroux
- Out of interest, why are the extra brackets added? Just so I fully understand the code I use.
They are needed because otherwise it won't parse the object correctly.
Taken from JSON.org: quote: The text must be wrapped in parens to avoid tripping on an ambiguity in JavaScript's syntax.
RE: RE: MySQL by ArkaneArkade on 05-03-2009 at 10:59 AM
Matti - Thanks for the info. Just helps. I prefer to use code I understand properly, rather than just anything that works.
quote: Originally posted by felipEx
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"}
]
}
I've changed the code output now to match yours, but I still get the same error. I've also tried just copying your json, but I still get the same error.
I've scanned my JSON output using the verifier at http://www.jslint.com/ and it says its all good (both mines, and yours) but still I get Error: Expected ')'. Any ideas?
|