#define DB Storage

Need some coding help with a MOD or tweak you are working on? - Ask here.
Forum rules
Ask for support specifically regarding coding help with phpBB3.
Not for generic usability questions or support.

#define DB Storage

Postby TimN » 29 Jul 2012, 13:38

If I define some constants in constants.php, then use a form to have people input data for things using those constants, is the constant stored in the database or the number it represents?

For example:
Code: Select all
// Define Category Weights
define('WEIGHT_LOW', 1);
define('WEIGHT_MED', 2);
define('WEIGHT_HIGH',3);


When I use a form to assign a weight, let's say 'WEIGHT_MED', what's stored in the database? WEIGHT_MED or 2?
If we decide to change the value of the weighting system later, I want to make sure it's not storing the defined numbers.

Thanks,
Tim
"Just smile and wave boys, smile and wave. Remember, cute and cuddly." - The Penguins
User avatar
TimN    
Supporter
Supporter
 
Posts: 372
Joined: 17 Nov 2008, 16:24
Location: Ceti Alpha V
Favorite Team: London Silly Nannies
Gender: Male
phpBB Knowledge: 5




phpBB Academy at StarTrekGuide
Support STG
Using PayPal Donate

Re: #define DB Storage

Postby Handyman » 29 Jul 2012, 19:55

No, constants are only stored in constants.php.
If you insert numbers into the database through SQL queries using the constants, you will have to update the numbers in the database if you decide to change them later.
Please contact me if you have any news to submit to SCOFF News.
SCOFFing at the candidates while you sleep.
My Mods || My Mod Queue
Image
User avatar
Handyman    
Rear Fleet Admiral
Rear Fleet Admiral
 
Posts: 7454
Joined: 08 May 2006, 04:45
Location: Where no man has gone before!
Favorite Team: Seattle Seahawks
Gender: Male

Re: #define DB Storage

Postby TimN » 30 Jul 2012, 10:23

Thanks.
I ran a quick test to see what would happen. I decided to use a constant to store in the database and a switch function to relate that to the defined constant. This way I can change the value of the defines later and not worry about what's stored. So for WEIGHT_LOW I'll store a 1, WEIGHT_MED and 2 and WEIGHT_HIGH a 3. But WEIGHT_LOW is defined as .5 right now. Later I can define it as 1, 2, 10, etc. But it'll always be the lowest weight and that'll always correlate to a 1 in the db.

Thanks for responding.
Tim
"Just smile and wave boys, smile and wave. Remember, cute and cuddly." - The Penguins
User avatar
TimN    
Supporter
Supporter
 
Posts: 372
Joined: 17 Nov 2008, 16:24
Location: Ceti Alpha V
Favorite Team: London Silly Nannies
Gender: Male
phpBB Knowledge: 5


Return to phpBB3 Coding Assistance

Who is online

Users browsing this forum: Exabot [Bot], Magpie Crawler and 18 guests