Author Topic: storing Data in DB vs. Arrays  (Read 1138 times)

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
storing Data in DB vs. Arrays
« on: April 30, 2007, 08:22:41 AM »
Starting with my new game, I was thinking about what is faster and what makes more sense for storing data.

Let's say there are...40 differnent units. Each unit is defined by ID, name, hp and strength. These values will not change any further.

Now what is better:

storing the units in a new table, storing them in different arrays (one for name, one for hp and one for strenght) or storing them in a multidimensional array (unit[1] = array("name"=>...);)?

Which one is the fastest, which one is the easiest to manage and what would you suggest to use in a game (personal preference)

- Sinzygy

Offline Broda

  • Level 13
  • *
  • Posts: 97
  • Reputation: +2/-0
    • View Profile
    • Nightfall Games
Re: storing Data in DB vs. Arrays
« Reply #1 on: April 30, 2007, 08:30:35 AM »
These values will not change any further.

The hp won't change?

You should probably store them in a table but if you are going to be doing a lot of processing in the script then read them into a multidim array indexed by the ID.

I haven't done a lot of stress testing on the PHP ADODB library but if you're going to be reading/rereading the information a lot during a script and array would probably be faster. Read the data once, close the recordset, do all of your processing, if you need to save something after the fact build 1 SQL string and execute it.

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: storing Data in DB vs. Arrays
« Reply #2 on: April 30, 2007, 09:18:03 AM »
These values will not change any further.

The hp won't change?

No, the values will be needed as base-values in a class. Further modifcations will be stored in a table (i see no other way to do this).
[as a side-note: there are about 6 "base-values" per unit which need to be stored]

This class will be called quite often and the unit-file [with the array(s)] inside will be quite large, so I was wondering what would slow the game more down.

Offline Broda

  • Level 13
  • *
  • Posts: 97
  • Reputation: +2/-0
    • View Profile
    • Nightfall Games
Re: storing Data in DB vs. Arrays
« Reply #3 on: April 30, 2007, 09:48:58 AM »
oh ok

I'm going to do something similar with my items - a base items table with the initial stats and an items table of the actual items that exist in the game that can have mods made to them

If I were you I'd run some tests. Stress test both options (multidim array & table) and have debug lines to track time, etc. If you can track the cpu usage that might be helpful too (i.e. which one puts more stress on your server).

If you're able to test this out, I'd love to see the results. If I get a chance I may try something like this on my server as well.

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: storing Data in DB vs. Arrays
« Reply #4 on: April 30, 2007, 10:04:04 AM »
Yeah, I guess I'll have to eventually do that. But not today... gotta plant a tree. Yay!

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: storing Data in DB vs. Arrays
« Reply #5 on: April 30, 2007, 10:04:41 AM »
I had been wondering the same thing with my game. I went for a database because I'm not so familiar with array functions.
But I used AdoDB and used the cache function to cache the data for a long time, then all subsequent queries to the information is taken from one cache file. I'm not sure how fast that is, but it doesn't require any extra database connections.

Offline Broda

  • Level 13
  • *
  • Posts: 97
  • Reputation: +2/-0
    • View Profile
    • Nightfall Games
Re: storing Data in DB vs. Arrays
« Reply #6 on: April 30, 2007, 11:07:49 AM »
But I used AdoDB and used the cache function to cache the data for a long time, then all subsequent queries to the information is taken from one cache file. I'm not sure how fast that is, but it doesn't require any extra database connections.

This adds another layer of tests. Not only would a test of a table be needed but also a table that is cached. The questions continue to build LOL

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: storing Data in DB vs. Arrays
« Reply #7 on: April 30, 2007, 11:24:36 AM »
And I'm still not using ADODB... how bad of me -_-

But yeah, if this proves even better, then I'll certainly switch/start using ADODB.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal