How to make sure that the fast-changing data from my MySQL DB is accurately represented in php scripts?

I have a database with a lot of game objects, which is requested by the following 3 PHP scripts.

  • List of objects: gets a JSON object with all the elements I need
  • Add Object: Adds an object to the database.
  • Reset: erases all objects from the table

All three of them work. Although, there is a mismatch of time. When a game calls the reset function, it restarts. When the game restarts, it automatically loads all objects. Unfortunately, here is the problem, if the game has just been reset, objects will still be pulled using script 1.

I know transactions, but I never used them, and I have no idea how to implement them here, since my transaction is related to things from different scenarios that run at different times.

For the bonus credit: will this setting (AS3> php> MySQL) cause me problems with heavy load? The game can be raised by 10, 100, 1000 people, is there anything I can read about this subject?

Edit: new idea / question

Currently, cleaning works as such: in the table of objects there is a field “deleted”, which is set to “1” when the reset method is called. It might be wiser to copy the existing data into the archive table and then truncate the living table ...

Edit: here is the (relevant) PHP code I'm using

Add object:

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);

List / Get objects:

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);

Reset: (EDIT 2)

mysql_query("LOCK TABLES bodies WRITE;");

$SQL = " DELETE FROM bodies";

if (!mysql_query($SQL))
  {
  die('Error: ' . mysql_error());
  }
};

mysql_query("UNLOCK TABLES;");
+3
1

MySQL.

, , , , reset , - . reset *. (* TRUNCATE . )

InnoDB Engine , . MyISAM .

, / , , , ROLLBACK.

. game_id game_id . . , .

, TRUNCATE . , TRUNCATE MySQL , .

, PHP/MySQL , , . , xdebug MySQL .

+1

All Articles