Greetings.
Newbie question here:
Do you have a rule of thumb on what to store in a database vs an associative array?
I read the documentation and watched/reimplemented the tutorials and a couple of published games. I understand the general recommendation that static information (e.g. all the cards in a deck, with attributes, etc.) are better stored in materials php file.
The doc says to consider database to store dynamic state information (e.g. card location, etc).
I suppose that the same can be achieved though with an associative array.
A simple database that has CARD_ID | CARD_LOCATION | CARD_STATE could be easily modeled also with the following array:
I suppose databases have better search capabilities with SELECT, while an array at some point would force you to cycle through its elements. Is that the reason?
In many cases I have seen, the code accesses the database only in very few occasions, and most of the operations are done with arrays at runtime.
So what are your reasons to use a database? What am I missing?
Newbie question here:
Do you have a rule of thumb on what to store in a database vs an associative array?
I read the documentation and watched/reimplemented the tutorials and a couple of published games. I understand the general recommendation that static information (e.g. all the cards in a deck, with attributes, etc.) are better stored in materials php file.
The doc says to consider database to store dynamic state information (e.g. card location, etc).
I suppose that the same can be achieved though with an associative array.
A simple database that has CARD_ID | CARD_LOCATION | CARD_STATE could be easily modeled also with the following array:
Code: Select all
$cards_snapshot = array(
$card_id => array(
"location" => $card_location;
"state" => $card_state;
)
)
In many cases I have seen, the code accesses the database only in very few occasions, and most of the operations are done with arrays at runtime.
So what are your reasons to use a database? What am I missing?