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 7863491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:29:51+00:00 2026-06-02T23:29:51+00:00

I can define constants in file and then include them, or I can store

  • 0
  1. I can define constants in file and then include them, or

  2. I can store them in DB and seed them.

From your experience, which one is better/faster/less resource costly for say .. dozens, hundreds, thousands defined?

  • 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-02T23:29:52+00:00Added an answer on June 2, 2026 at 11:29 pm

    This is an ever-present question, which differs from person to person, and is a bit of a balancing act. For me, it all depends on how big and static the data-set is presumed to be. In my applications I have about 10 code points where I will refer to constants rather than going through all the overhead to pull data from a database.

    Another benefit of using constants, is you can refer to them throughout the codebase which will help reduce defects and improve semantics, for example:

    class Ad
    {
        const ID_AD_TYPE_BANNER = 1;
        const ID_AD_TYPE_SKYSCRAPER = 2;
    }
    
    // Somewhere in app
    if (array_key_exists(Ad::ID_AD_TYPE_BANNER, $array)) {
    

    However there are a few hmmm downsides? I hesitate to call them downsides because they are not difficult to work around. First, if your constants are ints, and your application ever inputs these contants into a table, you will not be able to join to a ‘lookup’ table and see the lookup values as part of the query results. Instead you will just have to know what an id of 1 means in the query.

    Second, be sure to place constants in common sense locations, and try to namespace if you can, that way you can easily find the values if you end up forgetting what they are. If you have a clever IDE, it will do this for you. Also know that if a constant changes, you will have to do a code push vs manipulating database data directly.

    I’d say yes to constants, if the list is relatively small (<25) and not prone to change much, however, if your data won’t match these constraints, I would suggest popping them into a database.

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

Sidebar

Related Questions

In HTML/CSS you can define a style which can be applied to many types
I know that one can define an 'expected' exception in JUnit, doing: @Test(expect=MyException.class) public
In c\c++ can define: #ifndef <token> /* code */ #else /* code to include
We are using XML to define a schema for controlling the contents which can
I'm trying to read a list of numbers from a file and sort them
I can write into a relative file 1 , then when I try to
I can define default value in domain by this way : class ProcessingPriority {
I can define church numerals fairly easy using scheme: > (define f (lambda (x)
In C# you can define delegates anonymously (even though they are nothing more than
In core.php I can define Configure::write('Routing.admin', 'admin'); and /admin/controller/index will work. but if I

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.