I think if you were to provide more details as to what you are doing and how you are doing things you would possibly receive more help.
It seems you are asking people to read and understand your program and to offer you help based on that.
Firstly, could I suggest you tidy up your program, there are many blank lines that makes reading difficult.
It appears to be cobbled together from different routines you have grabbed.
Give it more documentation, at each routine and specific function, so it follows what you are doing.
To me, It appears you have set up a local server running SQL, is that correct?
You haven't scaled or done anything with your analog reading, it will be just raw and unfiltered, is that what you intend?
Why do you have a delay(3000) after you do a http GET?
You certainly have a lot of serial text being sent, and at a slow speed of 9600, I would suggest to rationalise this.
So, again, simply saying you want to control a relay using a web server is not providing much insight.
I am not intending to be critical, simply to let you know how I read your post.
PS, thanks zoomkat, thought you pass through with some code.