you are trying to pass a query from a webpage and then retireve and store the output, right?
then i suggest something like VB, java [i'm not telling that php isnt suitable], but these langages will be easier to manipulate in something like this