Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I make sure the rapidly changing data from my MySQL DB is accurately represented in php scripts?
    primarykey
    data
    text
    <p>I have a database with lots of game objects, which is being queried by the following 3 PHP scripts.</p> <ol> <li><strong>List objects:</strong> gets a JSON object with all the items I need</li> <li><strong>Add object:</strong> adds an object to the database</li> <li><strong>Reset:</strong> wipes all objects from the table</li> </ol> <p>All three of them work, somewhat. Although, there is a timing mismatch. When the game calls the reset function, it restarts. When the game restarts, it automatically loads all the objects. Unfortunately,and here's the problem, if the game has just been reset, objects will still be pulled by script 1.</p> <p>I know <em>of</em> transactions, but I have never used them and I have no idea how I would implement those here, since my transaction is involving things from different scripts that are run at different times.</p> <p>For bonus credit: will this setup (AS3 > php > MySQL) get me in trouble with a heavy load? The game might get picked up by 10, 100, 1000 people, is there anything I can read about that subject?</p> <p><strong>Edit: new idea/question</strong></p> <p>Currently, the wiping works as such: The objects table has a field 'deleted' which is set to '1' when the reset method is called. It might be smarter to copy the existing data into an archive table and then truncate the live table...</p> <p><strong>Edit: Here's the (relevant) PHP code I'm using</strong></p> <p>Add Object:</p> <pre><code>if ($db_found) { $x = $_GET['x']; $y = $_GET['y']; $type = $_GET['type']; $name = $_GET['name']; $text = $_GET['text']; $SQL = "INSERT INTO bodies (x,y,type,name,text) VALUES ('".$x."','".$y."','".$type."','".$name."','".$text."' )"; if (!mysql_query($SQL)) { die('Error: ' . mysql_error()); } }; mysql_close($db_handle); </code></pre> <p>List/Get Objects:</p> <pre><code>if ($db_found) { $SQL = "SELECT * FROM bodies WHERE deleted = 0"; $res = mysql_query($SQL); $rows = array(); while($r = mysql_fetch_assoc($res)) { print $r['x'] . ',' . $r['y'] . ',' . $r['type'] . ',' . $r['name'] . ',' . $r['text'] . ';'; } }; mysql_close($db_handle); </code></pre> <p>Reset: <strong>(EDIT 2)</strong></p> <pre><code>mysql_query("LOCK TABLES bodies WRITE;"); $SQL = " DELETE FROM bodies"; if (!mysql_query($SQL)) { die('Error: ' . mysql_error()); } }; mysql_query("UNLOCK TABLES;"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload