Sorry its kind of difficult to explain,
my current setup:
spark publish -> webhook -> PHP -> mySQL -> curl -> spark function
the spark publish triggers the webhook, the event name is message finished.the code on the core is
Spark.publish("messagefinished", NULL, 60, PRIVATE);
The webhook does a POST to my server containing a few things, like spark user ID and core ID and the event name, there is also some other stuff like time etc… exactly the same thing could be done with a TCPclient quite easily, and you could make the Post data match whats required by the PHP script.
the script then goes to my database and retrieves the latest message from the database, thats where the mysqli_query line comes into it, im not up to speed on how the database object and stuff works, its like magic stuff in the commentics library i use. the query returns a whole row of data into an array, its the oldest undisplayed message (as per the query) the PHP script then takes just the comment part of the array, which contains a message to display on the message torch.
the message is sent to the spark core using curl to call a function, this is the function on the core (in the setup() section)
Spark.function("addmessage", addMessage);
and after the main loop there is a function to deal with the comment sent to the core
int addMessage(String aText){
...
}
There is probably much simpler ways to do this, i just modified what was already written to get this going in the shortest time possible.
If i did it again i would do it with a TCPclient, do a post request to my PHP script with the query, and the result would be returned in the body. that way the PHP script does all the heavy work. same could be done for saving data, just include it in the POST, and you can use the key:value pair in the PHP script. Just make sure you think about security and SQL injections, i see attacks on my server on a daily basis. make sure you dont store anything without sanitizing it first, if anything thing looks sus its best to drop it and alert you, otherwise you could loose your whole database