Originally Posted by Old Pedant
But the big question: Will you update 1 or many records back in the DB?
If only 1 record, then quite frankly who cares you you do it?
And I might even suggest the sending data back to server via JSON isn't necessarily the best choice. But it's certainly workable.
Assuming you only need to update one record, and assuming that the JSON is as simple as you showed it, I'd probably just do
$json = $_GET["json"]; // or POST of course
$data = json_decode( $json, true ); // creates an associative array
$sql = "UPDATE table SET x = " . ( (int) $data["x"] ) . ", y = " . ( (int) $data["y"] )
. " WHERE name = '" . mysql_real_escape_string($data["name"]) . "' ";
And, really, even if you had multiple records to update, I'd do it similarly. One record at a time in a loop. MySQL does understand multi-record updates base on distinct keys. (It could do multi-record INSERTs, though you don't gain a whole bunch.)
Okay so from what I understand, there's no direct/built-in way to use a JSON to update MySQl, I simply need to loop through all attributes.
Actually, I think I'll go with only 1 VARCHAR(8000) containing all the info of my player so I got far more freedom for its attributes and it's easier for me to set into an array or update it.