简体   繁体   中英

Store permanent data on a php file to reduce the number of SQL queries is a good practice?

I´m creating a new website and in the webs I´ve coded before I always have been using a php file to store permanent that is used a lot that is called with an include from the index.php.

The purpose of that is to avoid doing extra queries as this data is used every time and doesn´t change, but now I´ve concerns if that is a good practice.

One example of that is the different languages options that the website has, that is shown everytime and I don´t want to do an extra query every time.

Is that a good practise or it´s better to store everything on the DB and make more queries?

I store my language dependent strings in separate files, grouped by function, for example email. So I would have a template called

lng_email

Then I add a suffix to it in the include statement. For English the example would be

lng_email_en.php

The suffix is fetched at login and stored in the session variable.

Well after 3 years since I posted the question, I end up storing the data the following way:

  • Almost all the data is stored in the mysql database, where it's easy to manage.
  • I use the $_SESSION var only for user's data that is being called and used during the user's session only.
  • I have a php file where I store general data that's being use a lot by the code and won't be changed in the short or mid term. This way I save the code to do several queries to the database. I store them within a function so they can be retrieved by other function and avoiding to declare them as a global . As an example:

     function retrieve_privacy_list(){ $privacy_list = array( 1=>'public', 2=>'reduced', 3=>'private'); return $privacy_list; } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM