Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7768207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:51:41+00:00 2026-06-01T15:51:41+00:00

I have a database with lots of game objects, which is being queried by

  • 0

I have a database with lots of game objects,
which is being queried by the following 3 PHP scripts.

  1. List objects: gets a JSON object with all the items I need
  2. Add object: adds an object to the database
  3. Reset: wipes all objects from the table

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.

I know of 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.

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?

Edit: new idea/question

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…

Edit: Here’s 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;");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:51:43+00:00Added an answer on June 1, 2026 at 3:51 pm

    How to do Transactions in MySQL.

    In your case you might be interessted in the atomicity and isolation of transactions, meaning that when restarting a game, you want to ensure that before the reset has not fully finished, nobody can fetch any of your intermediate data. Doing the reset inside a transaction will ensure this property*. (* for TRUNCATE see below)

    You will need InnoDB as your Engine for all tables that are involved in your transactions. MyISAM does not support transactions.

    Changing large amounts of data inside a transaction can potentially cause high query delays, as transaction use special undo/redo-logs to be able to undo all the things you did in your transaction, if you decide to ROLLBACK.

    I wouldn’t wipe the tables when starting a new game. Instead give your data a game_id and use a new game_id when starting a new game. Space shouldn’t really be an issue nowadays. This has the advantage that you will need little to none table locking when reseting the game.

    If you must, be sure to use TRUNCATE when clearing out the tables. As far as I know TRUNCATE in MySQL cannot be rolled back, so doing it inside a transaction won’t do anything useful.

    I think PHP/MySQL will perform fine if used correctly, even for larger visitor counts. You can use profiling tools like xdebug or the MySQL slow query log to trace and remove performance bottle necks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database generated page which shows lots of links. This page consists
I have the following table in a SQL Server 2008 database with lots of
I have a database object (a row), that has lots of properties (columns) that
Suppose the following scenario: I have a master database that contains lots of data,
Currently I have database with the following associations: One Client to Many Intakes One
I have a database that is filled with information for films, which is (in
Let's say I have a database filled with people with the following data elements:
I am doing lots of queries to my database with NSURLConnection Asynchronously, I have
I have a SQL Server database with lots of data and an empty MySQL
I have a huge database that has lots and lots of poorly documented constraints.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.