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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:47:07+00:00 2026-05-14T01:47:07+00:00

Currently all of my script’s settings are located in a PHP file which I

  • 0

Currently all of my script’s settings are located in a PHP file which I ‘include’. I’m in the process of moving these settings (about 100) to a database table called ‘settings’. However I’m struggling to find an efficient way of retrieving all of them into the file.

The settings table has 3 columns:

  • ID (autoincrements)
  • name
  • value

Two example rows might be:

admin_user            john
admin_email_address   john@example.com  

The only way I can think of retrieving each setting is like this:

$result = mysql_query("SELECT value FROM settings WHERE name = 'admin_user'");
$row = mysql_fetch_array($result);
$admin_user = $row['value'];

$result = mysql_query("SELECT value FROM settings WHERE name = 'admin_email_address'");
$row = mysql_fetch_array($result);
$admin_email_address = $row['value'];

etc etc

Doing it this way will take up a lot of code and will likely be slow.

Is there a better way?

  • 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-05-14T01:47:07+00:00Added an answer on May 14, 2026 at 1:47 am

    100 settings? Load them all at once. That will take no time at all. You absolutely do not want to load them one at a time.

    $result = mysql_query('SELECT * FROM settings');
    $settings = array();
    while ($row = mysql_fetch_assoc($result)) {
      $settings[$row['name']] = $row['value'];
    }
    

    If you need to compartmentalize these somehow, depending on how you need to do it, you could put a category or something on the table and then just load all the settings in a particular category.

    What I would suggest is abstracting this behind an object of some kind:

    class Settings {
      private $settings;
    
      public function __get($name) {
        if (!$this->settings)) {
          $result = mysql_query('SELECT * FROM settings');
          $this->settings = array();
          while ($row = mysql_fetch_assoc($result)) {
            $this->settings[$row['name']] = $row['value'];
          }
        }
        return $this->settings[$name];
      }
    }
    

    This way the settings aren’t loaded until you try and access one:

    $settings = new Settings;
    echo $settings->admin_name; // now they're loaded
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We currently have an error catching script for all our PHP sites. This script
I'm currently writing an msbuild script to publish a solution, which is all fine
I have set all of my PHP settings in the php.ini file to allow
I'm using Handlebars.js, and currently all my templates live inside script tags which live
I've currently got all of this mess at the top of my ViewModels which
Currently I'm trying to automatically generate a create script for all my SQL jobs
I have this script that I am currently running that works great for all
I'm currently working on a script which extracts data from two sources where one
I'm currently trying to make a page via php which allows the user to
What my script currently does: grabs & cleans a $_GET['id'] pulls all pre-existing data

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.